0

I am working on a project in Rails 4,previously i was using sqlite3 as a database,i switched to mysql database and changed all its configuration in database.yml file.I also got all my migrations successful while running rake db:migrate.

i was succesfull in ruinning rake db:dump

sudo gem install mysql

rake db:create

the problem i am facing is while running rake db:schema:load

i am getting the following error while running the above command

ActiveRecord::StatementInvalid: Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails: DROP TABLE `advance_salaries` CASCADE
/home/vh/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `_query'
/home/vh/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `block in query'
/home/vh/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.21/lib/mysql2/client.rb:79:in `handle_interrupt'
/home/vh/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.21/lib/mysql2/client.rb:79:in `query'

dont know why i am facing this issue.please help....................!!!!!!

8
  • reply is very urgent for me guys..........so please help..........if anyone knows the solution...... Commented Mar 26, 2017 at 5:10
  • all my project has stopped working... :/ Commented Mar 26, 2017 at 5:10
  • Could you add you schema.rb? Did you try just rake db:migrate instead of schema:load? Commented Mar 26, 2017 at 10:19
  • yes....rake db:schema:load..........but shows same error...!!! Commented Mar 26, 2017 at 12:34
  • create_table "advance_salaries", force: :cascade do |t| t.integer "employee_id" t.decimal "advance_amount", precision: 15, scale: 2 t.string "no_of_instalment" t.decimal "instalment_amount", precision: 15, scale: 2 t.date "advance_date" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "advance_type_id" t.decimal "interest", precision: 15, scale: 2 end Commented Mar 26, 2017 at 12:36

2 Answers 2

0

When you use db:schema:load, rails will clean your db and rebuild schema, and there is exist dependence in your db relation so it bring error.

The detail can reference :

ActiveRecord::StatementInvalid: Mysql2::Error: Cannot delete or update a parent row - Rails 4.2.6

Sign up to request clarification or add additional context in comments.

5 Comments

not helping........i was on sqllite database and switched to mysql database and i'm getting this error.Don't know how to solve this issue.......please help.....
i am able to migrate,only problem while doing rake db:load.
@puneet pls help....if youkniow the solution.....i am in great proble...whole my application has stopped...........!!!!!
i have an existing application which is running on sqlite3,so now i want to switch my entire application from sqlite to mysql.I changed all my configurationa nd also was successful in running rake db:migrate.Problem i'm facing while running rake db:schema:load.Dont know my my schema file is not loading.i want to backup all my existing application database from sqlite to mysql.
this is my new question link...please help.......... stackoverflow.com/questions/43061570/…
0

Try to follow below command:

rake db:drop
rake db:create
rake db:migrate
rake db:seed

1 Comment

thanks guys for all your reply.....i am successful in changing my dtabase from sqlite3 to mysql.But now i am getting strtime error in one of my file.The link for the question is...........stackoverflow.com/questions/43061570/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.