# Beginner mysql problem

**URL:** <https://discuss.rubyonrails.org/t/beginner-mysql-problem/28754>\
**Category:** rubyonrails-talk\
**Created:** [April 30, 2008, 4:31am UTC](https://discuss.rubyonrails.org/t/beginner-mysql-problem/28754 "2008-04-30T04:31:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donald1](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Donald1](https://discuss.rubyonrails.org/u/Donald1)\
**Post date:** [April 30, 2008, 4:31am UTC](https://discuss.rubyonrails.org/t/beginner-mysql-problem/28754/1 "2008-04-30T04:31:35Z")

</div>

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 &nbsp;&nbsp;def self.up &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create\_table "people" do |t| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column "id", :integer &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column "name", :string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column "address", :string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column "city", :string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column "state", :string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column "zipcode", :string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

&nbsp;&nbsp;def self.down &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;drop\_table :people &nbsp;&nbsp;end end

and the error is:

== ContactDb: migrating

---

<div class="post-metadata">

**Author:** ![Greg\_Donald1](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/greg_donald1/32/1313_2.png) [@Greg\_Donald1](https://discuss.rubyonrails.org/u/Greg_Donald1)\
**Post date:** [April 30, 2008, 2:39pm UTC](https://discuss.rubyonrails.org/t/beginner-mysql-problem/28754/2 "2008-04-30T14:39:05Z")

</div>

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:

t.integer :name

for example.

---

<div class="post-metadata">

**Author:** ![Roger\_Pack](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Roger\_Pack](https://discuss.rubyonrails.org/u/Roger_Pack)\
**Post date:** [April 30, 2008, 2:42pm UTC](https://discuss.rubyonrails.org/t/beginner-mysql-problem/28754/3 "2008-04-30T14:42:16Z")

</div>

try it without id

---

<div class="post-metadata">

**Author:** ![Donald1](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Donald1](https://discuss.rubyonrails.org/u/Donald1)\
**Post date:** [April 30, 2008, 2:47pm UTC](https://discuss.rubyonrails.org/t/beginner-mysql-problem/28754/4 "2008-04-30T14:47:25Z")

</div>

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?

thanks again

---

<div class="post-metadata">

**Author:** ![Pardee\_Roy](https://avatars.discourse-cdn.com/v4/letter/p/f0a364/32.png) [@Pardee\_Roy](https://discuss.rubyonrails.org/u/Pardee_Roy)\
**Post date:** [April 30, 2008, 3:14pm UTC](https://discuss.rubyonrails.org/t/beginner-mysql-problem/28754/5 "2008-04-30T15:14:48Z")

</div>

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 &nbsp;&nbsp;def self.up &nbsp;&nbsp;&nbsp;&nbsp;create\_table :people do |t| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.string :first\_name, :null =\> false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.string :last\_name, :null =\> false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.integer :organization\_id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.string :personal\_url &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.string :voice\_number &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.string :cell\_number &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.string :email\_address, :null =\> false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.date :birth\_date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.text :notes &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;execute("alter table people add constraint fk\_organizations foreign key (organization\_id) references organizations (id)") &nbsp;&nbsp;end

&nbsp;&nbsp;def self.down &nbsp;&nbsp;&nbsp;&nbsp;drop\_table :people &nbsp;&nbsp;end end

HTH,

-Roy
