Reputation: 595
I am taking over a Rails project that has a populated schema.rb file but oddly it doesn't have a migrate folder and no migrate files. I am so new to the language but doesn't the schema file get created based on the migration files? If I run "rake db:migrate", the existing table in the schema file gets deleted. Does this mean that the previous developer manually edited the schema file? Could I have deleted the migrate files when installing Ruby/Rails?
Also, the logs display this error:
PG::UndefinedTable: ERROR: relation "nameoftable" does not exist
Does this have to do with the fact that there are no migrate files?
I am working on creating the migrate files right now but I wanted to confirm I am understanding this correctly.
Thanks in advance.
Upvotes: 2
Views: 1120
Reputation: 176412
doesn't the schema file get created based on the migration files?
Yes, but they can survive independently. I can create my schema and modify it with several migrations, then delete the migrations before sending the project to you.
Rails will still start fine as what he cares about is the content of the schema.rb
file.
If you want to construct your database, you should load the schema from schema.rb
and not using rake db:migrate
. In a very large and long-lived Rails project, you are not guaranteed that all the migrations will be able to run all from the first one to the end.
The way you setup a database is using the command
rake db:schema:load
Then from there you can move forward creating new migrations in the future. You don't really need the old migration files.
Upvotes: 5