I’m a little new to migrations, and would appreciate any help…
This is the migration I am attempting to run:
class CreateEmployees < ActiveRecord::Migration
def self.up
create_table :employees do |t|
t.column :id, :integer, :null => false
t.column :user_name, :string, :null => false, :limit => 32
t.column :first_name, :string, :limit => 32
t.column :last_name, :string, :limit => 32
t.column :mod_dt, :datetime, :null => false
end
end
def self.down
drop_table :employees
end
end
After running ‘rake migrate’, I receive this as an error message:
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), user_name
varchar(32) NOT NULL, first_name
varchar(32) DEFAULT NULL, ' at line 1: CREATE TABLE employees (
idint(11) DEFAULT NULL auto_increment PRIMARY KEY(11),
user_namevarchar(32) NOT NULL,
first_namevarchar(32) DEFAULT NULL,
last_namevarchar(32) DEFAULT NULL,
mod_dt` datetime NOT NULL)
ENGINE=InnoDB
Correct me if I’m wrong, but it seems that the MySQL error is
happening because the migrations is passing an apostrophe " ’ " around
the column names, i.e. ‘user_name’, ‘id’, etc.
Why would migrations create an incorrect SQL string?
Thanks very much for any help.