I'm developing a web application using Rails, but I'm having trouble solving the error when running rails db:migrate.
The error resulted in the model name used in the second argument of add_reference being mistakenly entered in the migration file. I entered sub_places where I should have entered subplaces.
At that time, the error message displayed on the terminal will be 1 below.
An error occurred during migration, so when I checked rails db:migrate:status, the status of the file was still dowm. Since the migration file was down, rewriting the spelling and running rails db:migrate again, the following error message 2 appears.
Probably, even though the migration file is down, the parts other than add_reference :posts, :subplace, foreign_key: true are reflected in the database.
The software Sequel Pro used for database management reflects the contents of the migration file.
Is there a solution for this situation?
Thanks for your response.
Applicable source code
Error message 1 Mysql2::Error: Table'App name_development.sub_places' doesn't exist: SHOW FULL FIELDS FROM `sub_places` Error message 2 Mysql2::Error: Duplicate column name'lunch_name': ALTER TABLE `posts` ADD `lunch_name` varchar(255)
What I tried
#Migration file class AddDetails2ToPosts
Please refer to this article.
Once empty the migration file, run rails db:migrate, run rails db:rollback with status up, fix spelling and run rails db:migrate again.
The result is the same as error message 2 above.
Answer # 1
I solved it by directly deleting unnecessary columns using SQL
・Points that took time
The foreign key could not be simply deleted because it had a foreign key constraint.
ALTER TABLE posts DROP COLUMN foreign key;
SHOW CREATE TABLE posts;
(To the right of CONSTRAINT is the foreign key constraint name)
Check the foreign key constraint name with
ALTER TABLE posts DROP FOREIGN KEY foreign key constraint name;
The foreign key was successfully deleted by executing.
After that, I could restore the schema file to the state before the change and reflect the migration file with rails db:migrate.
- ruby - about integration test errors
- ruby - about errors after deploying heroku
- ruby on rails - about routing errors in devise
- ruby - i'm using the errors method, but i don't get an error message
- about android studio errors
- android studio - [flutter] about errors in screen transitions
- ruby on rails: about nomethoderror that occurred when adding a good function
- ruby - i have a question about rails routing errors
- errors related to mql4 functions
- ruby on rails - search for related models
- ruby on rails - about the problem that rails test does not become green in rails tutorial
- ruby on rails - about the code of the adjacency list model implemented in rails
- ruby on rails - about rails unit test code
- ruby on rails - [rails] about the display position after redirect by pressing like
- ruby on rails - about bundler of dockerfile when deploying rails application to ec2
- ruby - rails unable to resolve user errors
- about api errors in python
- ruby on rails - about rails:
- ruby - about the error when there is no id of the association destination
- ruby on rails - has_many related, but how to use it like has_one
- ruby - i want to resolve mysql2 :: error :: connectionerror (unknown mysql server host'db' (0)): that occurred while deploying t
- ruby - [rails] when rails s is executed, an error "cannot load database configuration" appears and it is forcibly term
- ruby - the time on the rails browser and the time on the database (sequel ace) are different
- i want to get the value of the ruby embed code of the erb file with jquery
- ruby - i want rails controller @user = userwhere (logged user's date of birth + -3 years)
- ruby - i want to create a database on aws
- ruby - rails + aws + rds + mysql shortly describe partial match search (fuzzy search) for all columns
- i want to output all ruby on rails flash messages
- ruby - how to create a seed file associated with user
- ruby - i can't get the value from the array i earned with news-api