Forum: Ruby on Rails Issue running migrations from MySQL...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
KendallJ (Guest)
on 2007-02-23 18:06
(Received via mailing list)
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 (`id`
int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `user_name`
varchar(32) NOT NULL, `first_name` varchar(32) DEFAULT NULL,
`last_name` varchar(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.
EgonJGF (Guest)
on 2007-02-23 18:40
(Received via mailing list)
I think the ID field is generated automatically.

I got the same error you did, using your code.  Removing the ID field
line from the create table block got rid of the error.
KendallJ (Guest)
on 2007-02-23 18:41
(Received via mailing list)
Wow, thanks a lot man.
This topic is locked and can not be replied to.