Migrations are pending

Asked

Viewed 71 times

0

I’m new to Rails and I’m also learning how to use databases. I’m trying to create a blog that currently has a table that already contains some data. What happens is that I was using the notebook to develop the blog and now when I cloned it from git to my PC, the data I had in the table is gone. When I spin rails server get that mistake:

Migrations are pending.
To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development".

By running this code it creates a table without the data I already had in it. What I am doing wrong and how can I recover the data?

  • but where’s the database file? if it’s outside your git repository it won’t go up in the commit itself (if it’s in gitignore tb)

  • I was able to solve it using this Gem : https://github.com/rroblak/seed_dump. Basically he saved the data in the file Seeds.Rb and then filled the table for me. Thank you very much xD

1 answer

1


The error you received indicates that there are migrations that your database has not yet applied. As you said, you had switched computers.

The database is local and is not versioned by Git for clear reasons. As far as I’m concerned, you’re using Sqlite, which makes it easy to change environments. All you have to do is copy the file db/development.sqlite3 from one environment to another. This file is by default ignored in .gitignore created by Rails, as it should not be committed.

If you were using another DBMS, such as Mysql or Postgresql, you would have to create a backup of the database and upload it to the other environment.

The file of Seed does not serve to "create a backup" of the database, but a clean and initial version of the application. That is, fill a table of cities, countries, create an admin user, and other things like.

  • I understand Vinicius, thank you so much for your guidance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.