# Newbie Migrations issue

**URL:** <https://www.ruby-forum.com/t/newbie-migrations-issue/88981>\
**Category:** Rails\
**Created:** [March 16, 2007, 4:34am UTC](https://www.ruby-forum.com/t/newbie-migrations-issue/88981 "2007-03-16T04:34:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9de0a6/32.png) [@gabriel](https://www.ruby-forum.com/u/gabriel)\
**Post date:** [March 16, 2007, 4:34am UTC](https://www.ruby-forum.com/t/newbie-migrations-issue/88981/1 "2007-03-16T04:34:18Z")

</div>

I’m taking a crack at Rails and have run into a snag fairly early on.  
I read a tutorial that showed me how to use migrations and everything  
was going fine until I actually tried to use what I’d written.

First off, I’m using Windows XP, MySQL 5.0.19, rails 2.2, ruby 1.8.5.

I used this little script to verify the connection to the database was  
working:

[http://blog.caboo.se/articles/2005/8/4/test-your-database-connection-in-rails](http://blog.caboo.se/articles/2005/8/4/test-your-database-connection-in-rails)

The migration file is pretty simple. So simple it’s probably not the  
problem.

class BankDb \< ActiveRecord::Migration  
def self.up  
create\_table “accounts” do |t|  
t.column “id”, :integer  
t.column “name”, :string  
end  
end  
def self.down  
drop\_table “accounts”  
end  
end

# g:\sites\bank\db\migrate\>rake db:migrate VERSION=1 (in g:/sites/bank) == BankDb: migrating

– create\_table(“accounts”)  
rake aborted!  
Mysql::Error: You have an error in your SQL syntax; check the manual  
that corresponds to your MySQL server version for the right syntax to  
use near ‘(  
11), `name` varchar(255) DEFAULT NULL) ENGINE=InnoDB’ at line 1:  
CREATE TABLE accounts (`id` int(11) DEFAULT NULL auto\_increment  
PRIMARY KEY(11), `nam e` varchar(255) DEFAULT NULL) ENGINE=InnoDB

I logged into MySQL and tried the SQL statement generated but changed  
“PRIMARY KEY(11)” to simply “PRIMARY KEY” and it worked. I assume  
there’s a version mismatch with the syntax Rails expects MySQL to  
understand and what my version of MySQL really does understand.

I haven’t had much luck with web searches for things like `rails migrations primary key` or `migrations mysql syntax issues` or,  
well, anything else I thought up. I assume I just need to update  
“migrations” but googling `rails upgrade migrations` and the like  
doesn’t do much good either. Obviously it’s something obvious that all  
rails guys know and don’t have to look up. 😉

What am I missing? =(

Thanks!

---

<div class="post-metadata">

**Author:** ![gabriel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9de0a6/32.png) [@gabriel](https://www.ruby-forum.com/u/gabriel)\
**Post date:** [March 16, 2007, 4:45am UTC](https://www.ruby-forum.com/t/newbie-migrations-issue/88981/2 "2007-03-16T04:45:19Z")

</div>

Gabriel wrote:

> def self.down  
> Mysql::Error: You have an error in your SQL syntax; check the manual  
> there’s a version mismatch with the syntax Rails expects MySQL to  
> understand and what my version of MySQL really does understand.
> 
> I haven’t had much luck with web searches for things like `rails migrations primary key` or `migrations mysql syntax issues` or,  
> well, anything else I thought up. I assume I just need to update  
> “migrations” but googling `rails upgrade migrations` and the like  
> doesn’t do much good either. Obviously it’s something obvious that all  
> rails guys know and don’t have to look up. 😉
> 
> What am I missing? =(

Try taking out the t.column “id” line. Rails will create it by default  
unless you specifically tell it not to so having it there is redundant  
and may be causing a problem. Also the convention is to use symbols for  
the column names as in:

t.column :name, :string

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![gabriel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9de0a6/32.png) [@gabriel](https://www.ruby-forum.com/u/gabriel)\
**Post date:** [March 16, 2007, 5:16am UTC](https://www.ruby-forum.com/t/newbie-migrations-issue/88981/3 "2007-03-16T05:16:20Z")

</div>

> Try taking out the t.column “id” line.

=O

It’s the little things in life, no?

Thank you Michael!

---

<div class="post-metadata">

**Author:** ![gabriel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9de0a6/32.png) [@gabriel](https://www.ruby-forum.com/u/gabriel)\
**Post date:** [March 23, 2007, 6:56pm UTC](https://www.ruby-forum.com/t/newbie-migrations-issue/88981/4 "2007-03-23T18:56:50Z")

</div>

Michael W. wrote:  
…

> –  
> Michael W.

Thank you! I had the exact same problem! Now its fixed.

---

<div class="post-metadata">

**Author:** ![gabriel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9de0a6/32.png) [@gabriel](https://www.ruby-forum.com/u/gabriel)\
**Post date:** [March 16, 2007, 7:14am UTC](https://www.ruby-forum.com/t/newbie-migrations-issue/88981/5 "2007-03-16T07:14:27Z")

</div>

Rails automatically adds an ‘id’ field for you, so you don’t have to  
declare it yourself. Try the following instead:

class BankDb \< ActiveRecord::Migration  
def self.up  
create\_table “accounts” do |t|  
t.column “name”, :string  
end  
end  
def self.down  
drop\_table “accounts”  
end  
end
