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)
Related
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
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 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)
Some of my rSpec tests are failing and I suspect it's due to the test database not being cleared out. When I try to run rake db:test:prepare, I'm getting the error below (i'm in Rails 3.2). Clearly, this looks like some kind of Postgres issue, looks like the rake task is trying to drop the test database so it can repopulate it. Production database schema loads fine.
I've looked for the rake task in lib/tasks/ but I haven't been able to find it. Anyone have any idea on what's going on?
osx_user-> rake db:test:prepare
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: DROP DATABASE IF EXISTS ""
^
: DROP DATABASE IF EXISTS ""
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
Figured it out. My database.yml file for the development environment was set like this:
database: <%= ENV['DATABASE_NAME_TEST'] %>
The rake task was looking for an environmental variable that did not exist.