Rick R
2010-Jul-30 06:36 UTC
newb here trying to understand an issue with rolling back migrations then re-running them
I''m sure this is total newb (since I am pretty newb) but I''m curious what the issue is here. I attempt to role back all my migrations which I''m doing with rake db:migrate VERSION=0 (in /Users/rick/projects/rails/sillymeters) == CreateSessions: never migrated, skipping ================================= == CreateUsers: reverting ===================================================-- drop_table(:users) -> 0.0011s == CreateUsers: reverted (0.0012s) ========================================== == CreateMeters: reverting ==================================================-- drop_table(:meters) -> 0.0008s == CreateMeters: reverted (0.0009s) ========================================= etc.. Note the first one says "CreateSessions: never migrated, skipping" When I then go to run the migrations, most go through fine, but then I get the following error when it tries to run the CreateSessions migration: ~/projects/rails/sillymeters(master) $ rake db:migrate (in /Users/rick/projects/rails/sillymeters) == CreateSessions: migrating ================================================-- create_table(:sessions)- rake aborted! An error has occurred, this and all later migrations canceled: SQLite3::SQLException: table "sessions" already exists: CREATE TABLE "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "session_id" varchar(255) NOT NULL, "data" text, "created_at" datetime, "updated_at" datetime) I''m assuming that each application has its own instance of SQLLite so I''m curious how this error is occurring or what I need to do to fix it. I ''think'' I might be getting this because it''s possible I did at one point have a similar migration that created the Session table, but then I deleted that migration and created it as a new one with a new name. The table name was the same though "sessions" so I don''t get what is going on. The migration in question looks like: class CreateSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.string :session_id, :null => false t.text :data t.timestamps end add_index :sessions, :session_id add_index :sessions, :updated_at end def self.down drop_table :sessions end end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Jul-30 08:22 UTC
Re: newb here trying to understand an issue with rolling back migrations then re-running them
> > Note the first one says "CreateSessions: never migrated, skipping" > > When I then go to run the migrations, most go through fine, but then I get > the following error when it tries to run the CreateSessions migration: > > ~/projects/rails/sillymeters(master) $ rake db:migrate > (in /Users/rick/projects/rails/sillymeters) > == CreateSessions: migrating > ================================================> -- create_table(:sessions)- > rake aborted! > An error has occurred, this and all later migrations canceled: > > SQLite3::SQLException: table "sessions" already exists: CREATE TABLE > "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "session_id" > varchar(255) NOT NULL, "data" text, "created_at" datetime, "updated_at" > datetime) > > I''m assuming that each application has its own instance of SQLLite so I''m > curious how this error is occurring or what I need to do to fix it. I > ''think'' I might be getting this because it''s possible I did at one point > have a similar migration that created the Session table, but then I deleted > that migration and created it as a new one with a new name. The table name > was the same though "sessions" so I don''t get what is going on. >Rails tracks migrations that have be run with the schema_migrations (which contains the numerical identifier for each migration). If you created a new migration then that migration won''t be recorded as having being run (which is why migrate VERSION=0 doesn''t do anything) but the table is of course still there, so trying to create it again raises an error Fred> The migration in question looks like: > > class CreateSessions < ActiveRecord::Migration > def self.up > create_table :sessions do |t| > t.string :session_id, :null => false > t.text :data > t.timestamps > end > > add_index :sessions, :session_id > add_index :sessions, :updated_at > end > > def self.down > drop_table :sessions > end > end-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Patrick Robertson
2010-Jul-30 11:45 UTC
Re: newb here trying to understand an issue with rolling back migrations then re-running them
You can run the following command: script/dbconsole And then manually drop the sessions table (drop sessions). Then try full rollbacks and migrations again. Sent from my iPhone On Jul 30, 2010, at 2:36 AM, Rick R <rickcr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m sure this is total newb (since I am pretty newb) but I''m curious what the issue is here. I attempt to role back all my migrations which I''m doing with > > rake db:migrate VERSION=0 > (in /Users/rick/projects/rails/sillymeters) > == CreateSessions: never migrated, skipping =================================> > == CreateUsers: reverting ===================================================> -- drop_table(:users) > -> 0.0011s > == CreateUsers: reverted (0.0012s) ==========================================> > == CreateMeters: reverting ==================================================> -- drop_table(:meters) > -> 0.0008s > == CreateMeters: reverted (0.0009s) =========================================> > etc.. > > Note the first one says "CreateSessions: never migrated, skipping" > > When I then go to run the migrations, most go through fine, but then I get the following error when it tries to run the CreateSessions migration: > > ~/projects/rails/sillymeters(master) $ rake db:migrate > (in /Users/rick/projects/rails/sillymeters) > == CreateSessions: migrating ================================================> -- create_table(:sessions)- > rake aborted! > An error has occurred, this and all later migrations canceled: > > SQLite3::SQLException: table "sessions" already exists: CREATE TABLE "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "session_id" varchar(255) NOT NULL, "data" text, "created_at" datetime, "updated_at" datetime) > > > I''m assuming that each application has its own instance of SQLLite so I''m curious how this error is occurring or what I need to do to fix it. I ''think'' I might be getting this because it''s possible I did at one point have a similar migration that created the Session table, but then I deleted that migration and created it as a new one with a new name. The table name was the same though "sessions" so I don''t get what is going on. > > The migration in question looks like: > > class CreateSessions < ActiveRecord::Migration > def self.up > create_table :sessions do |t| > t.string :session_id, :null => false > t.text :data > t.timestamps > end > > add_index :sessions, :session_id > add_index :sessions, :updated_at > end > > def self.down > drop_table :sessions > end > end > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
gbesch
2010-Jul-31 13:22 UTC
Re: newb here trying to understand an issue with rolling back migrations then re-running them
Check to see if you have duplicate code in any of your migrations to create this table:> SQLite3::SQLException: table "sessions" already exists: CREATE TABLE > "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "session_id" > varchar(255) NOT NULL, "data" text, "created_at" datetime, "updated_at" > datetime)This can easily happen if you have code to create all your tables in the main CreateDatabase migration file, then run script/generate to generate scaffolding or a model for an existing table. The generator script will create a new migration with table creation code, causing rake to choke the next time you do a migration. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.