Reputation: 129
Rails 6, development with sqlite3.
My schema.rb has a file that shouldn't be there: no migration files (On current git branch) says it should be generated. By it's name I can see it's from an earlier branch that I abandoned, and wen't back to try a different approach to building my rails app.
To double check: I get a name error when I try to access the table in the Rails Console, so it's only there in the schema file, but not in the Database itself.
Can I force rails to run and or confirm that current schema is matching the migration files and if not matching, would run the migration?
Edit/Update: I need to clarify that I have 6 migration files, that I went over to make sure none of them were from the earlier abandoned branch.
(admins is the table at issue)
ActiveRecord::Base.connection.tables
in the rails commandline generates:
["schema_migrations", "ar_internal_metadata", "events", "admins", "details"]
When I do Event
I get the columns name and type. But when I do Admin I get
Traceback (most recent call last):
1: from (irb):3
NameError (uninitialized constant Admin)
So the issue is: How do I correctly reset the database to
Upvotes: 0
Views: 495
Reputation: 129
running rails db:migrate:reset removed seem to have fixed the issue:
My schema file does not have the 'admins' in it, and it does not show up when running ActiveRecord::Base.connection.tables
in rails commandline.
I believe this was caused by Git, as it has the DB in the files: /db/*.sqlite3
and that 'admins' was created on a branch I abandoned earlier and never merged. So it was kept in the database, but the migration files were removed when I went back and created a new branch earlier on the timeline.
Upvotes: 0
Reputation: 56
The schema.rb file is auto-generated from the current state of the database, so just run rails db:migrate
to re-generate schema.rb file
Upvotes: 1