I am using heroku to deploy my rails app. I am trying to seed some data in the production by running the command heroku run rake db:seed. However, the command is not working. I am not able to seed files in production. The seeds.rb file is given below.
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
# end
5.times do
Scoreboard.create!(name_of_scoreboard: "scoreboard_abc",
name_of_organization: "abcdef",
name_of_activity: "ghijklmn",
user_id: 1,
states: "state",
country: "state",
cities: "state")
end
I get the following message in the terminal when I run the command.
$ heroku run rake db:seed
Running rake db:seed on ⬢ app... up, run.4751
ActiveRecord::SchemaMigration Load (2.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
I run `heroku restart` but the objects isn't seeded in the production database. I have tried seeding this file in development and it works perfectly. I am not sure what's wrong.
running heroku run rake db:setup gives me the following error
DETAIL: User does not have CONNECT privilege.
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/app/vendor/ruby-2.2.4/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/app/vendor/ruby-2.2.4/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
I also get the following errors.
psql:/app/db/structure.sql:955: ERROR: multiple primary keys for table "mailboxer_conversation_opt_outs" are not allowed
psql:/app/db/structure.sql:963: ERROR: multiple primary keys for table "mailboxer_conversations" are not allowed
psql:/app/db/structure.sql:971: ERROR: multiple primary keys for table "mailboxer_notifications" are not allowed
psql:/app/db/structure.sql:979: ERROR: multiple primary keys for table "mailboxer_receipts" are not allowed
psql:/app/db/structure.sql:987: ERROR: multiple primary keys for table "managers" are not allowed
psql:/app/db/structure.sql:995: ERROR: multiple primary keys for table "pg_search_documents" are not allowed
psql:/app/db/structure.sql:1003: ERROR: multiple primary keys for table "pictures" are not allowed
psql:/app/db/structure.sql:1011: ERROR: multiple primary keys for table "requests" are not allowed
psql:/app/db/structure.sql:1027: ERROR: multiple primary keys for table "scoreboards" are not allowed
psql:/app/db/structure.sql:1035: ERROR: multiple primary keys for table "statuses" are not allowed
psql:/app/db/structure.sql:1043: ERROR: multiple primary keys for table "team_matches" are not allowed
psql:/app/db/structure.sql:1051: ERROR: multiple primary keys for table "team_members" are not allowed
psql:/app/db/structure.sql:1059: ERROR: multiple primary keys for table "teams" are not allowed
psql:/app/db/structure.sql:1067: ERROR: multiple primary keys for table "topics" are not allowed
psql:/app/db/structure.sql:1075: ERROR: multiple primary keys for table "users" are not allowed
psql:/app/db/structure.sql:1082: ERROR: relation "index_categories_on_scoreboard_id" already exists
psql:/app/db/structure.sql:1089: ERROR: relation "index_documents_on_category_id" already exists
psql:/app/db/structure.sql:1096: ERROR: relation "index_events_on_scoreboard_id" already exists
psql:/app/db/structure.sql:1103: ERROR: relation "index_favourites_on_scoreboard_id" already exists
psql:/app/db/structure.sql:1110: ERROR: relation "index_favourites_on_user_id" already exists
psql:/app/db/structure.sql:1117: ERROR: relation "index_favourites_on_user_id_and_scoreboard_id" already exists
psql:/app/db/structure.sql:1124: ERROR: relation "index_invitations_on_scoreboard_
I think I am running the migration files that already exist. As a result, I am getting a uniqueness error.
I think you have migrations pending. You can try:
Heroku run rake db:migrate db:seed
Try these steps,
heroku run rake db:schema:load
heroku run rake db:migrate
heroku run rake db:seed
Related
On a project I'm working on, rake db:drop db:create db:migrate db:seed won't work. It raises undefined method 'my_attribute=' for #<MyObject:0x00007fd1af863908> error when running the db:seed task. There is seemingly nothing preventing MyObject calling my_attribute - it's a very standard enum field. If you remove the field a similar undefined method error occurs on other standard fields such a datetime field.
However, running rake db:drop db:create db:migrate, then rails console, exiting the console, then running rake db:seed works fine.
Has anyone experienced this?
EDIT:
The entire error is:
rake aborted!
NoMethodError: undefined method `my_attribute=' for #<MyObject:0x00007fa53bae34d0>
/Users/Will/.gems/ruby/2.5.0/gems/activemodel-5.2.2/lib/active_model/attribute_methods.rb:430:in `method_missing'
/Users/Will/.gems/ruby/2.5.0/gems/pg_search-2.1.6/lib/pg_search.rb:81:in `method_missing'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/attribute_assigner.rb:16:in `public_send'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/attribute_assigner.rb:16:in `block (2 levels) in object'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/attribute_assigner.rb:15:in `each'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/attribute_assigner.rb:15:in `block in object'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/attribute_assigner.rb:14:in `tap'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/attribute_assigner.rb:14:in `object'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/evaluation.rb:13:in `object'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/strategy/create.rb:9:in `result'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/factory.rb:43:in `run'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/factory_runner.rb:29:in `block in run'
/Users/Will/.gems/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:170:in `instrument'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/factory_runner.rb:28:in `run'
/Users/Will/.gems/ruby/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
/my-project/db/seeds.rb:449:in `<top (required)>'
Where seeds.rb 499 is a factorybot.create task:
valid_opportunity = FactoryBot.create(:opportunity,
slug: 'french-sardines-required',
title: 'French sardines required',
response_due_on: 9.months.from_now,
author: editor,
service_provider: paris,
countries: [france],
sectors: [agriculture],
types: [private_sector],
values: [hundred_thousand],
created_at: 2.weeks.ago,
first_published_at: Time.zone.today,
source: :post,
status: :publish)
In the model we have:
class MyModel < ApplicationRecord
enum my_attribute: { pending: 1, publish: 2, draft: 3, trash: 4 }
end
Note that my_attribute is a real field in the database, and also that if the line around my_attribute is removed, a different field in the database for this model flags up a similar error.
If you plan to do this all in 1 shot then in db:seed you will need to call ModelName.reset_column_information for each model you intend to interact with.
The reason for this is when the code is loaded the class ModelName does not have a table. The dynamic attribute methods are loaded from the table columns but since there is no table, there are no columns, and thus no methods. This result is cached with the model to avoid having to make this round trip every time you reference the model.
Calling reset_column_information causes ModelName to reset this cache. This way the next time this model is referenced it will go back to the table (that now exists), reload all the columns (that now exist), and dynamically generate the methods pertinent to these columns.
You must do this anytime you plan to:
create a table or add columns to a table and;
change the data in that table or new column during the same task run
Please note same task run does not necessarily mean same migration or even same task itself. It can be any migration or seeding that could occur to complete the full run of a given task(s) like db:migrate or in your case db:migrate db:seed
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 was messing with my database, creating and deleting tables. I deleted few migration files after pushing them to heroku. Previously I created a table 'moms'. Later I wanted to rename it, so I deleted 'moms' and created new table 'minutes_of_meetings'. I did $rake db:migrate and everything was done successfully and my app is running perfectly on localhost.
After pushing it to heroku, when I did $heroku run rake db:migrate, it generated the following log:
ActiveRecord::SchemaMigration Load (0.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to DropMoms (20150823142852)
(0.6ms) BEGIN
== 20150823142852 DropMoms: migrating =========================================
-- drop_table(:moms)
(0.9ms) DROP TABLE "moms"
PG::UndefinedTable: ERROR: table "moms" does not exist
: DROP TABLE "moms"
(0.5ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: table "moms" does not exist
: DROP TABLE "moms"/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
I created a new table 'moms' in heroku so that it can be deleted when migration runs. I did this:
$ heroku run Ruby console for rails-app-name >> ActiveRecord::Migration.create_table :moms
I also created a migration to create table 'moms'. But still the error persists.
EDIT:
This is my CreateMoms migration file:
class CreateMoms < ActiveRecord::Migration
def change
create_table :moms do |t|
t.string :name
t.timestamp null: false
end
end
end
When I run heroku run rake db:migrate:up
Running `rake db:migrate:up` attached to terminal... up, run.1729
rake aborted!
VERSION is required
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:78:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:up
(See full trace by running task with --trace)
WARNING: Toolbelt v3.41.3 update available.
On heroku run rake db:migrate:down
Running `rake db:migrate:down` attached to terminal... up, run.6389
rake aborted!
VERSION is required - To go down one migration, run db:rollback
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:down
(See full trace by running task with --trace)
WARNING: Toolbelt v3.41.3 update available.
Caution
rake db:schema:load will wipe away all of your data from the heroku database. Please make sure you have your data backup on heroku. If you already don't have backup of your heroku database, you can easily do so by using Heroku PGBackups
Looks like your schema is messed up. Just load the schema to the database using rake db:schema:load and then run the migration again:
heroku run rake db:schema:load
heroku run rake db:migrate
When I run rake db:migrate I get following output:
== 20141219011612 CreatePost: migrating =======================================
-- create_table("posts") rake aborted! StandardError: An error has occurred, this and all later migrations canceled:
== 20141219011612 Postposts: migrating =======================================
-- create_table("posts") rake aborted! StandardError: An error has occurred, this and all later migrations canceled:
PG::DuplicateTable: ERROR: relation "posts" already exists : CREATE
TABLE "posts" ("id" serial primary key, "post" text, "release_date"
timestamp, "created_at" timestamp, "updated_at" timestamp)
/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in
async_exec' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in block in execute'
/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:373:in block in log' /home/admin/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/notifications/instrumenter.rb:20:in instrument'
/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:367:in log' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in execute'
/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in
create_table' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:649:in block in method_missing'
/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in
block in say_with_time' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in say_with_time'
/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:641:in
`method_missing'
...
migrate' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in block (2 levels) in <top (required)>' Tasks: TOP => db:migrate (See
full trace by running task with --trace)
I don't understund how this is possible, bescause In scheme file I don't have post table.
Somehow, you ended up with a table named 'posts' in your database. Perhaps from a prior migration that you deleted without rolling back? If you don't care about any of your data in the database, you can run
rake db:drop db:create db:migrate
to bring your development database inline with your current migrations.
If you have data in other tables you don't want to lose, open the database console and drop the posts table manually:
$ rails db
# drop table posts;
Then run db:migrate again.
For those who didn't get your answer above
In my case, I had been working on a feature a month ago the field happens to be created at that time. Now when I try to run migration rake db: migrate I see this error. I know and am sure that this is not here due to any mistake.
I also tried to rollback that particular migration
rake db:migrate:down VERSION=20200526083835
but due to some reason, it did nothing, and to move further I had to comment out the up method in that migration file.
# frozen_string_literal: true
class AddColToAccounts < ActiveRecord::Migration
def up
# execute 'commit;'
#
# add_column :accounts, :col, :boolean,
# null: false,
# default: false
end
def down
execute 'commit;'
remove_column :accounts, :col
end
end
And, now I am able to run the migrations.
At last, I undo the commenting thing and I am done.
Thanks
Check your db/schema.rb
You most likely have the same table being created there in addition to a migration in db/migrate/[timestamp]your_migration
You can delete the db/migrate/[timestamp]your_migration if it is a duplicate of the one found in the schema and it should work.
In case this helps anyone else, I realized that I had been using a schema.rb file that was generated while using MySQL. After transitioning to Postgres, I simply forgot I would need to run rake db:migrate before I could use rake db:schema:load
One of the hack I found was to put pry before you are creating the table on the migration file.
require 'pry'
binding.pry
create_table :your_table_name
and drop that table:
drop_table :your_table_name
After that you can remove the drop_table line and it will work fine!
kill the current postgres process:
sudo kill -9 `ps -u postgres -o pid`
start postgres again:
brew services start postgres
drop, create, and migrate table:
rails db:drop db:create db:migrate
This will delete your data, don't do it on production.
First remove the orphan migration ********** NO FILE ********** in case you have any, by executing this db command:
delete from schema_migrations where version='<MIGRATION_ID>';
then
rails db:schema:load
then
rails db:migrate
This worked for me.
I had the same problem, the only thing that worked for me was to delete the table from within the rails console, like so:
ActiveRecord::Migration.drop_table(:products)
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.