Hi all, I used the generate script to make a bunch of table migrations, resulting in files like 002_bookmarks.rb, 003_tags.rb, etc. When I did the ''rake migrate'', the db was set up but more migration files appeared, now called 009_create_bookmarks.rb, 010_create_tags.rb, etc. Now when I want to change the database (add a table or column, alter the schema) I do ./script/generate migration do_something_new and rake migrate gives me: (in /home/jason/Svn/working/trunk) ** Invoke migrate (first_time) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment** Execute db:migrate== CreateBookmarks: migrating =================================================\ -- create_table(:bookmarks) -- create_table(:bookmarks) rake aborted!Mysql::Error: Table ''bookmarks'' already exists: CREATE TABLE bookmarks (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY) ENGINE=InnoDB It looks like it''s trying to build everything from the ground up, but of course it can''t because that''s already done. I thought rake was only supposed to run the new migrations you make after the last rake migrate. Do I have to create destructive migrations to start over? If anyone''s run into this before, a helpful nudge would be great. Thanks! -Jason PS: Mysql''s permissions/grants are turned off so it''s not an authorization problem.
Jason Frankovitz wrote:> Hi all, > > I used the generate script to make a bunch of table migrations, > resulting in files like 002_bookmarks.rb, 003_tags.rb, etc. When I > did the ''rake migrate'', the db was set up but more migration files > appeared, now called 009_create_bookmarks.rb, 010_create_tags.rb, > etc. Now when I want to change the database (add a table or column, > alter the schema) I do ./script/generate migration do_something_new > and rake migrate gives me: > > (in /home/jason/Svn/working/trunk) > ** Invoke migrate (first_time) > ** Invoke db:migrate (first_time) > ** Invoke environment (first_time) > ** Execute environment** > Execute db:migrate== CreateBookmarks: migrating > =================================================\ > -- create_table(:bookmarks) > -- create_table(:bookmarks) > rake aborted!Mysql::Error: Table ''bookmarks'' already exists: CREATE > TABLE bookmarks (`id` int(11) DEFAULT NULL auto_increment PRIMARY > KEY) ENGINE=InnoDB > > It looks like it''s trying to build everything from the ground up, but > of course it can''t because that''s already done. I thought rake was > only supposed to run the new migrations you make after the last rake > migrate. Do I have to create destructive migrations to start over? > > If anyone''s run into this before, a helpful nudge would be great. > > Thanks! > -Jason > > PS: Mysql''s permissions/grants are turned off so it''s not an > authorization problem.I ran into what I think your experiencing. I created my base migration file, ran it but then later, throughout the development of the app I was working on, I had to generate new Models. After I would create these new models, I would go and add them to my base migration doc as well. Doing that, I ran into the exact same problem you''re seeing. I would rake migrate but it would error out telling me one of my tables already exist (which it did at that point). Basically, script/generating Models creates their migration doc as well so you don''t have to. What I''ll do in the future is either not script/generate migration files anymore and just use what gets created when I generate models. -- Posted via http://www.ruby-forum.com/.
Jason, Try this. Figure out what version your database is at. Take a look at the schema table to find out the version. Then, what I would suggest, is to step back version by version using the command "rake migrate VERSION=16" (for example). Step back and forth until you find the guilty party. What could be happening is that you have an empty migration that is made by a model and then you made another one later that trys to make the table again. So, you should either edit the original migration to add the needed columns, or fix the new migration to alter the table instead. In the future, you can generate a model without a migration by doing "script/generate model mymode --skip-migration" HTH, Ryan On 6/21/06, noobonrails <curtis.edmond@gmail.com> wrote:> > Jason Frankovitz wrote: > > Hi all, > > > > I used the generate script to make a bunch of table migrations, > > resulting in files like 002_bookmarks.rb, 003_tags.rb, etc. When I > > did the ''rake migrate'', the db was set up but more migration files > > appeared, now called 009_create_bookmarks.rb, 010_create_tags.rb, > > etc. Now when I want to change the database (add a table or column, > > alter the schema) I do ./script/generate migration do_something_new > > and rake migrate gives me: > > > > (in /home/jason/Svn/working/trunk) > > ** Invoke migrate (first_time) > > ** Invoke db:migrate (first_time) > > ** Invoke environment (first_time) > > ** Execute environment** > > Execute db:migrate== CreateBookmarks: migrating > > =================================================\ > > -- create_table(:bookmarks) > > -- create_table(:bookmarks) > > rake aborted!Mysql::Error: Table ''bookmarks'' already exists: CREATE > > TABLE bookmarks (`id` int(11) DEFAULT NULL auto_increment PRIMARY > > KEY) ENGINE=InnoDB > > > > It looks like it''s trying to build everything from the ground up, but > > of course it can''t because that''s already done. I thought rake was > > only supposed to run the new migrations you make after the last rake > > migrate. Do I have to create destructive migrations to start over? > > > > If anyone''s run into this before, a helpful nudge would be great. > > > > Thanks! > > -Jason > > > > PS: Mysql''s permissions/grants are turned off so it''s not an > > authorization problem. > > > > I ran into what I think your experiencing. I created my base migration > file, ran it but then later, throughout the development of the app I was > working on, I had to generate new Models. After I would create these new > models, I would go and add them to my base migration doc as well. Doing > that, I ran into the exact same problem you''re seeing. I would rake > migrate but it would error out telling me one of my tables already exist > (which it did at that point). Basically, script/generating Models > creates their migration doc as well so you don''t have to. What I''ll do > in the future is either not script/generate migration files anymore and > just use what gets created when I generate models. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ryan Prins rprins@gmail.com http://www.lazyi.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060621/46549539/attachment.html