$ rake db: migrate An error occurred, this and all subsequent migrations were canceled

I am new to RoR and I keep getting this error message:

$ rake db:migrate == CreateUsers: migrating ==================================================== -- create_table(:users) rake aborted! An error has occurred, this and all later migrations canceled: SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar (255), "created_at" datetime, "updated_at" datetime) Tasks: TOP => db:migrate (See full trace by running task with --trace) 

I have been looking for a solution for 3 days, but I can not find anything that works for me.

Thank you in advance for your help :) PS - I'm running from Windows.

+7
source share
5 answers

table "users" already exists seems to be a problem. Have you tried to manually delete a table from your database using the SQLITE administration tool ?

Or you can include the deletion table in your migration script (it should be called create_users.rb inside your db / migrate folder). Inside def up enter drop_table :users :

  def up drop_table :users create_table :users do |t| t.string :name #... t.timestamps end 

Oh, and I remember from my RoR time that the name of the Users table can cause problems later. Perhaps this is due.

+7
source

Not sure if you follow Michael Hartle's RoR Guide.

But someone said that the problem is in the steps of the http://archive.railsforum.com/viewtopic.php?id=44944 tutorial

rake db:drop:all <---------- will destroy everything , then run rake db:migrate again to fix the problem.

Luck

+7
source

Since the table already exists, you need to delete / delete it before performing the migration.

An easy, GUI way to do this is with the SQLite Database Browser ( http://sourceforge.net/projects/sqlitebrowser/ ).

Click the button using the Table-X icon. Select "User Table", click "Delete."

Then run rake db:migrate

Bada boom bada bing

+1
source

I had a similar problem, then I did => rake db:drop => rake db:create => rake db:migrate

worked fine.

But if that doesn't work, we can try something like

ActiveRecord::Migration.drop_table('users')

ActiveRecord::Migration.create_table('users')

0
source

I had the same problem and after a few hours I finally found a solution

I put def self.up

create_table: users do | t |

go down drop_down: users end end

Then make a rake db: migrate and magic !!!!

0
source

Source: https://habr.com/ru/post/904236/


All Articles