mysql - RoR scaffold add field after script/generate -
i generated scaffold , put in type:value need add field / db column how add type:value without destroying , restarting whole project?
rake aborted! mysql::error: have error in sql syntax; check manual corres ponds mysql server version right syntax use near '(11), `titl e` varchar(255) default null, `artist_old` varchar(255) default null,' @ line 1 : create table `albums` (`id` int(11) default null auto_increment primary key(11 ), `title` varchar(255) default null, `artist_old` varchar(255) default null, `r elease_date` datetime default null, `genre` varchar(255) default null, `feature` int(11) default null, `image_path` varchar(255) default null, `created_at` date time default null, `updated_at` datetime default null, `artist_id` int(11) defau lt null) engine=innodb
usually when use scaffold command create migration in db/migrate/
folder, containing database setup model, example:
class createcomments < activerecord::migration def self.up create_table :comments |t| t.text :body end end def self.down drop_table :comments end end
if have not run rake db:migrate
command after created scaffold, can edit migration file under db/migrate/
, add field missed in beginning. after edited file, run rake db:migrate
command apply migration database.
if stepped through rake db:migrate
after creating scaffold, can create new migration script/generate migration addsubjectcolumntocomments
add field table. in example above, new migration , fill in following code:
class addsubjectcolumntocomments < activerecord::migration def self.up add_column :subject, :comments, :string end def self.down remove_column :subject, :comments end
good luck migrating!
Comments
Post a Comment