i tried running rake bd:migrate but it gave me an error and told me to run rails db:migrate RAILS_ENV=development instead but it gave me bunch of errors
C:\Sites\seekhostel.com>rails db:migrate RAILS_ENV=development
== 20180311182801 AddDeviseToUsers: migrating =================================
-- change_table(:users)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:7:in `block in up'
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:7:in `block in up'
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
SQLite3::SQLException: duplicate column name: email
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:7:in `block in up'
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
i would love to know why it did so and how to fix it
By looking at error message I suspect two things happened here:
You already had users table (because new migration has change_table(:users), not create_table(:users) - devise generator recognize that)
You ran $ rails generate devise command and you didn't inspect autogenerated migration file.
You were supposed to remove line
t.string :email, null: false, default: ""
from 20180311182801_add_devise_to_users.rb file
Related
i created a comment controller in rails but if i run the server it gives an error in db migrate.
Caused by:
SQLite3::SQLException: table "comments" already exists
C:/Users/SIBI/Desktop/rails1/hello_world/db/migrate/20190516103017_create_comments.rb:3:in `change'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I installed a gem acts-as-taggable-on whenever i tried to run rails db:migrate it would output this:
C:\Sites\novosti>rails db:migrate
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:2:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:2:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
So i just added [5.1] and it fixed the problem but another one appeared
C:\Sites\novosti>rails db:migrate
== 20170708123900 ActsAsTaggableOnMigration: migrating ========================
-- create_table(:tags)
-> 0.0028s
-- create_table(:taggings)
-> 0.0033s
-- add_index(:taggings, :tag_id)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Index name 'index_taggings_on_tag_id' on table 'taggings' already exists
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:23:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
ArgumentError: Index name 'index_taggings_on_tag_id' on table 'taggings' already exists
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:23:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Index name on a table should be unique. So this is an error from db as the the index already exists. Please drop the index on the table of the db before migration or you can remove the add_index in migration if the index is already ok in the table
I'm using rails to build an application which allows users to authorize and connect to the Twitter API using their Twitter account. The log in works, but i have a problem with the posts (i'm using this gem): when i try to run rails db:migrate i get this error:
$ rails db:migrate
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DuplicateTable: ERROR: relation "tweets" already exists
: CREATE TABLE "tweets" ("id" serial primary key, "user_id" integer, "body" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
C:/Users/......./db/migrate/20170419185735_create_tweets.rb:3:in `change'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "tweets" already exists
: CREATE TABLE "tweets" ("id" serial primary key, "user_id" integer, "body" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
C:/Users/......./db/migrate/20170419185735_create_tweets.rb:3:in `change'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
PG::DuplicateTable: ERROR: relation "tweets" already exists
C:/Users/......./db/migrate/20170419185735_create_tweets.rb:3:in `change'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
== 20170419185735 CreateTweets: migrating =====================================
-- create_table(:tweets)
I'm new to rails so any help would be appreciated!
I'm reinstalling the paperclip gem but encountered an error when trying to run the migration. (Note: I only deleted the original migration file from text editor). Specifically, when I ran:
$ rake db:migrate
I encountered:
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: image_file_name: ALTER TABLE "pins" ADD "image_file_name" varchar
c:/Users/Jaye/Desktop/inspireboard/db/migrate/20160929074428_add_attachment_image_to_pins.rb:4:in `block in up'
c:/Users/Jaye/Desktop/inspireboard/db/migrate/20160929074428_add_attachment_image_to_pins.rb:3:in `up'
c:in `migrate'
ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: image_file_name: ALTER TABLE "pins" ADD "image_file_name" varchar
c:/Users/Jaye/Desktop/inspireboard/db/migrate/20160929074428_add_attachment_image_to_pins.rb:4:in `block in up'
c:/Users/Jaye/Desktop/inspireboard/db/migrate/20160929074428_add_attachment_image_to_pins.rb:3:in `up'
c:in `migrate'
SQLite3::SQLException: duplicate column name: image_file_name
c:/Users/Jaye/Desktop/inspireboard/db/migrate/20160929074428_add_attachment_image_to_pins.rb:4:in `block in up'
c:/Users/Jaye/Desktop/inspireboard/db/migrate/20160929074428_add_attachment_image_to_pins.rb:3:in `up'
c:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
After seeing the above, I tried to run rake db:drop , but encountered:
Permission denied # unlink_internal
Could anyone suggest how to work around this? (Note: I'm using Windows 8, rails 4.2.5.1, paperclip 4.3.7)
Appreciate a lot!
Removing the development.sqlite3 file and rerun db:migrate solved the problem!
Check if you close the Rails Server to run the rake db:drop. I was having the same issue, and then you reinstall the papperclip. I hope that I helped.
I have tried rake db:migrate and I can't seem to fix this problem. Anyone know where to begin? I have looked at most of the other pending migration error on StackOverflow and can't seem to find a solution.
Note: Running rails on Windows
After I run rake db:migrate:
DL is deprecated, please use Fiddle
-- add_index(:conversations, :sender_id)
-- add_index(:conversations, :sender_id)
rake aborted!
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: main.conversations: CREATE INDEX "index_conversations_on_sender_id" ON "conversations" ("sender_id")
C:/Users/Jason/Documents/GitHub/TruTechEventPlanner/db/migrate/20151118013432_create_chats.rb:13:in `<class:CreateChats>'
C:/Users/Jason/Documents/GitHub/Planner/db/migrate/20151118013432_create_chats.rb:1:in `<top (required)>'
C:in `disable_ddl_transaction'
SQLite3::SQLException: no such table: main.conversations
C:/Users/Jason/Documents/GitHub/Planner/db/migrate/20151118013432_create_chats.rb:13:in `<class:CreateChats>'
C:/Users/Jason/Documents/GitHub/Planner/db/migrate/20151118013432_create_chats.rb:1:in `<top (required)>'
C:in `disable_ddl_transaction'
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: main.conversations: CREATE INDEX "index_conversations_on_sender_id" ON "conversations" ("sender_id")
C:/Users/Jason/Documents/GitHub/Planner/db/migrate/20151118013432_create_chats.rb:13:in `<class:CreateChats>'
C:/Users/Jason/Documents/GitHub/Planner/db/migrate/20151118013432_create_chats.rb:1:in `<top (required)>'
C:in `disable_ddl_transaction'
SQLite3::SQLException: no such table: main.conversations
C:/Users/Jason/Documents/GitHub/Planner/db/migrate/20151118013432_create_chats.rb:13:in `<class:CreateChats>'
C:/Users/Jason/Documents/GitHub/Planner/db/migrate/20151118013432_create_chats.rb:1:in `<top (required)>'
C:in `disable_ddl_transaction'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)