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.
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 am a new ROR developer. We are developing an application using Rails and AngularJS. A brief background of what I was trying to do:
Another developer developed an application (partial) named hiredjob. I have to continue development with his application changing the name of the application to hiredtoday and also changing all the models from admin_X to X . For that following is the sequence of steps I follow:
Method 1:
Copy the old hiredjob application to a new application hiredtoday.
Delete all db/migrate.
rails generate devise admin.
rake db:migrate gives error
Error from rake db:migrate:
home/arshi/.rvm/gems/ruby-2.2.3/gems/devise-
3.5.2/lib/devise/rails/routes.rb:485:in `raise_no_devise_method_error!': Admin does not respond to 'devise' method. This usually means you haven't loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb' (RuntimeError)
On searching solution for above on the internet, I comment devise_for :admins in config/route.rb
After which on running rake db:migrate again I got an error.
Error is as follow:
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'hiredjob_development.admins' doesn't exist: ALTER TABLE 'admins' ADD 'email' varchar(255) DEFAULT '' NOT NULL/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `query'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `block in execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:231:in `execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:573:in `block (3 levels) in <class:Table>'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:572:in `each'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:572:in `block (2 levels) in <class:Table>'
Note: I have also tried to do run: rake db:drop db:create db:migrate. But still does not work.
i think you are getting this error because devise depends on the table already having been created. you need to:
1) delete the devise migration
2) write a migration to create the admins table http://guides.rubyonrails.org/active_record_migrations.html#creating-a-table
3) regenerate the devise migration.
I created a migration named AddEntryTOMembers entry:decimal. Then I needed to change the decimal to integer. When I ran rake db:rollback, it rolled back successfully but when I retried running rails g AddEntryTOMembers entry:integer it shows:
SQLite3::SQLException: duplicate column name: entry: ALTER TABLE "members" ADD "
entry" integerc:/Sites/roomapp/db/migrate/20150216143625_add_entry_to_members.rb
:3:in `change'
c:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Then I searched on Stack Overflow and found "SQLite3::SQLException: duplicate column name while migrating". After that I ran rake db:migrate VERSION=0
and it rolled back all the migrations.
But when I ran rake db:migrate again it shows a problem with my previous successful adding migration.
SQLite3::SQLException: duplicate column name: image: ALTER TABLE "members" ADD "
image" varcharc:/Sites/roomapp/db/migrate/20150206144138_add_image_to_members.rb
:3:in `change'
c:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
How do I re-migrate all of my migrations?
I am new to both Ruby and Rails. So this may be an easy fix. I'm sorry if it is.
I recently installed Ruby-on-Rails and started following the tutorial on rubyonrails.org which shows how to make a simple blog. Everything was running fine until I got to section 5.5. I went to run db:migrate and it gave me an error.
|D:\Documents\Programs\Ruby\blog>rake db:migrate
== 20141216061542 CreateArticles: migrating ===================================
-- create_table(:articles)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "articles" already exists: CREATE TABLE "articles" ("id" INTEGER
PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "text" text, "created_at" datetime,
"updated_at"
datetime) D:/Documents/Programs/Ruby/blog/db/migrate/20141216061542_create_articles.rb:3:in
`change
'
C:in `migrate'
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "articles" already exists: CREATE
TABLE
"articles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "text" text,
"created_at" datetime, "updated_at" datetime)
D:/Documents/Programs/Ruby/blog/db/migrate/20141216061542_create_articles.rb:3:in `change'
C:in `migrate'
SQLite3::SQLException: table "articles" already exists
D:/Documents/Programs/Ruby/blog/db/migrate/20141216061542_create_articles.rb:3:in `change'
C:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I fired up the server to see what it would show and it gave me this:
ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
It's been doing this ever since. I have tried starting over by deleting the project.(not entirely sure if that was a good move.) I have tried looking over the code. Nothing I have tried has given me any hints on what to do.
Is there any way to get rid of these errors?
Thank you in advance.
EDIT:
I tried to reset the database with 'rake db:reset', but it just gave me this:
|D:\Documents\Programs\Ruby\blog\app\views\articles>rake db:reset
(in D:/Documents/Programs/Ruby/blog)
Permission denied # unlink_internal - D:/Documents/Programs/Ruby/blog/db/development.sqlite3
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/fileutils.rb:1460:in `unlink'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/fileutils.rb:1460:in `block in remove_file'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/fileutils.rb:1468:in `platform_support'
...
rake aborted!
Errno::EACCES: Permission denied # unlink_internal -
D:/Documents/Programs/Ruby/blog/db/development.
sqlite3
Tasks: TOP => db:schema:load
(See full trace by running task with --trace)
I shortened it for readability.
And here is my create_articles migration file:
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.timestamps
end
end
end
You've already created that particular table. Try this from your terminal:
rake db:drop db:create db:migrate
Or:
rake db:reset db:migrate
So basically, you will start your database from scratch, which will avoid the current error.
Note that for new migrations, you only run the 'rake db:migrate' command otherwise your existing data will be lost.
Later on if you come across this problem in a production environment, ensure that you do 'something else' - surely you wouldn't want to sacrifice your production database data.
Well It seems obvious, you already have table articles, and you are trying to create a new one.
Two options:
comment migration with articles do rake db:migrate, uncomment for other environment (if any)
clear database and run migrations again.
Add create_articles to your question as well, could help resolving the problem.
Drop the db
rake db:drop
And Migrated it once again
rake db:migrate
You have already create articles tables. So you need to drop it and migrate it once again.
I'm getting this error after trying to update a gem (mailboxer) and removing it.
Mysql2::Error: Table 'conversations' already exists: CREATE TABLE conversations (id int(11) DEFAULT NULL auto_increment PRIMARY KEY, subject varchar(255) DEFAULT '', created_at datetime NOT NULL, updated_at datetime NOT NULL)
I tried:
Bundle exec rake db:migrate rollback then rake db:migrate
Bundle exec rake db:migrate v= xxxxxxxx then rake db:migrate
getting rid of the migration files (that worked but I don't like the though of just getting rid of code)
I do not want to loose my data and drop the tables.
Any thoughts?
Update:
Rake db:migrate:status
up 20140526010413 Adduserfollowme to users
up 20140703193119 Add vote weight to votes
up 20140713211140 Add partime to user
up 20140716024440 Add devise to admin users
up 20140716024510 Create active admin comments
up 20140727042518 ********** NO FILE **********
up 20140727051902 Add slug to activities
down 20140728031732 Create mailboxer.mailboxer engine
down 20140728031733 Add notified object.mailboxer engine
down 20140728031734 Add notification code.mailboxer engine
down 20140728031735 Add attachments.mailboxer engine
down 20140728031736 Rename receipts read.mailboxer engine
down 20140728031737 Add global notification support.mailboxer engine
rake db:rollback
== AddSlugToActivities: reverting ============================================
-- remove_index("activities", {:column=>:slug})
-> 0.0215s
-- remove_column("activities", :slug)
-> 0.0342s
== AddSlugToActivities: reverted (0.0559s) ===================================
Rake db:migrate
== AddSlugToActivities: migrating ============================================
-- add_column(:activities, :slug, :string)
-> 0.0266s
-- add_index(:activities, :slug)
-> 0.0104s
== AddSlugToActivities: migrated (0.0373s) ===================================
== CreateMailboxer: migrating ================================================
-- create_table(:conversations)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'conversations' already exists: CREATE TABLE `conversations` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `subject` varchar(255) DEFAULT '', `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `block in execute'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:170:in `create_table'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/foreigner-1.6.1/lib/foreigner/connection_adapters/abstract/schema_statements.rb:14:in `create_table'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:432:in `create_table'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:466:in `block in method_missing'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in `block in say_with_time'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in `say_with_time'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:458:in `method_missing'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:334:in `method_missing'
/home/bill/apps/woomatch/releases/20140728100705/db/migrate/20140728031732_create_mailboxer.mailboxer_engine.rb:6:in `up'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:370:in `up'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in `block in migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:389:in `migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:in `migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:777:in `call'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:777:in `ddl_transaction'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:in `block in migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in `each'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in `migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:in `up'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:in `migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
What should I do next?
There is no rake db:migrate rollback, only rake db:rollback
Try rake db:migrate:status, then use rake db:rollback to make unwanted migrations to be down.
Sometimes when 'something went wrong' and you migrate-rollback a lot, it is necessary to comment up some lines, make migrate\rollback and incomment them again.
If it doesnt work, try show code of migrations that fail