Going through Lynda’s 2010 tutorial on rails and have been stuck on migration for the past couple of days. When running
$ rake db:migrate
I get
NOC-4:app noc$ rake db:migrate
(in /Users/noc/rails_projects/app)
== CreateUsers: migrating ====================================================
— create_table(:users)
rake aborted!
An error has occurred, all later migrations canceled:
Mysql::ServerError::ParseError: 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 ” at line 1: CREATE TABLE users (id int(11) DEFAULT NULL auto_increment PRIMARY KEY, first_name varchar(25), last_name varchar(50), email varchar(255) DEFAULT ” NOT NULL, created_at datetime, updated_at datetime, password varchar(#)) ENGINE=InnoDB
(See full trace by running task with –trace)
=================================
NOC-4:app noc$ mysql –version
mysql Ver 14.14 Distrib 5.5.20, for osx10.6 (i386) using readline 5.1
Below is my migrate file (create_users.rb):
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string "first_name", :limit => 25
t.string "last_name", :limit => 50
t.string "email", :default => "", :null => false
t.string "password", :limit =>
t.timestamps
end
end
def self.down
drop_table :users
end
end
========================================
My rails version and gem list below:
NOC-4:app noc$ rails --version
Rails 3.1.3
NOC-4:app noc$ gem list
*** LOCAL GEMS ***
actionmailer (3.1.3)
actionpack (3.1.3)
activemodel (3.1.3)
activerecord (3.1.3)
activeresource (3.1.3)
activesupport (3.1.3)
ansi (1.4.1)
arel (2.2.1)
builder (3.0.0)
bundler (1.0.21 ruby)
coffee-rails (3.1.1)
coffee-script (2.2.0)
coffee-script-source (1.2.0)
erubis (2.7.0)
execjs (1.2.13)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
json (1.6.4)
libv8 (3.3.10.4 x86_64-darwin-11)
mail (2.3.0)
mime-types (1.17.2)
multi_json (1.0.4)
mysql (2.8.1)
pg (0.12.2)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.1)
rack-mount (0.8.3)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.1.3)
railties (3.1.3)
rake (0.8.7)
rdoc (3.12)
ruby-mysql (2.9.4)
sass (3.1.12)
sass-rails (3.1.5)
sprockets (2.0.3)
sqlite3 (1.3.5)
therubyracer (0.9.9)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
turn (0.8.2)
tzinfo (0.3.31)
uglifier (1.2.1)
=========================================================
I think you need to complete the limit for your password field.
The problem is that
t.timestampsends up being the value for your limit, as you can read from the resulting sql in the error explanation:password varchar(#)) ENGINE=InnoDBNOTE: you shouldn’t use a plain text field for a password. If you’re using rails 3.1 this could help you with this: http://railscasts.com/episodes/270-authentication-in-rails-3-1