I am new to rails and have come across a problem with a sample
application I was working on.
When trying to use rake migrate I got the error listed below.
my db file contains the following
class ContactDb < ActiveRecord::Migration
create_table "people" do |t|
t.column "id", :integer
t.column "name", :string
t.column "address", :string
t.column "city", :string
t.column "state", :string
t.column "zipcode", :string
and the error is:
== ContactDb: migrating
Rails adds an id field for you, unless you tell it not to. So leave yours out.
Also, you might check out the new column syntax for use with
create_table. You can do less now:
It worked. Thanks!
But out of curiosity what was wrong with the original setup?
Does rails not support the addition of an id field without explicitly
telling it not to add its own, or is there something else going wrong?
Try leaving out the spec for the id column--rails will add that for you.
Also--I don't know if it matters (probably doesn't) but if you're using
the current version of rails, there's a new syntax for migrations.
Here's my create_people, FWIW:
class CreatePeople < ActiveRecord::Migration
create_table :people do |t|
t.string :first_name, :null => false
t.string :last_name, :null => false
t.string :email_address, :null => false
execute("alter table people add constraint fk_organizations foreign
key (organization_id) references organizations (id)")