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
def self.up
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
end
end
def self.down
drop_table :people
end
end
and the error is:
== ContactDb: migrating
– create_table(“people”)
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, address
varchar(255) DEFAULT NULL, ci' at line 1: CREATE TABLE people (idint(11) DEFAULT NULL auto_increment PRIMARY KEY(11),namevarchar(255) DEFAULT NULL,addressvarchar(255) DEFAULT NULL,cityvarchar(255) DEFAULT NULL,statevarchar(255) DEFAULT NULL,zipcode` varchar(255) DEFAULT NULL) ENGINE=InnoDB
I’m using a default install.
I noticed that the value supplied to PRIMARY KEY was the number 11.
Any suggestions.
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: