Changing a field ending in id and renaming it, removes the id column in migrations
Reported by Kieran P | March 1st, 2010 @ 11:53 PM
Changing a field ending in id and renaming it, removes the id column in migrations
Here is basically what I did:
script/generate JobAssignment job_id:integer user_id:integer
script/generate hobo_migration (generate and migrate)
[
change JobAssignment.rb and renamed user_id to staff_id
also add: belongs_to :staff, :class_name => "User", :foreign_key => :id
]
script/generate hobo_migration (enter staff_id to rename then migrate
Result:
SQLite3::SQLException: duplicate column name: id: ALTER TABLE "job_assignments" ADD "id" integer
Cause:
The following is in the migration:
rename_column :job_assignments, :user_id, :staff_id
add_column :job_assignments, :id, :integer
Notice that it makes the id column again, yet it already exists as evident from the SQL error.
Comments and changes to this ticket
-
Matt Jones March 3rd, 2010 @ 02:42 AM
Those
belongs_to
in your examples are incorrect -:foreign_key
specifies the name of the field on the object declaringbelongs_to
, not on the associated object. So in your Project example above,projects.client_id
refers toclients.id
(using DB field names). What exactly are you trying to achieve with:foreign_key
here? -
Matt Jones September 14th, 2011 @ 09:42 PM
- State changed from new to invalid
- Milestone order changed from 0 to 0
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
People watching this ticket
Referenced by
- 650 Multiple belongs_to only uses one See my comments on #648. :foreign_key is not used correct...
- 653 belongs_to with a :foreign_key incorrectly uses it for form fields This is very likely triggered by the problem in #648. Ple...