First of all, what is dump from database (DB) to seeds file? I didn't know what `` `dump``` means at first. .. And I used to copy commands and codes in full, and when an error or trouble occurred, I didn't know what to do and my senior helped me. At times like this, it's a good idea to understand what your code is doing so you can think about what's happening and what's causing it.
A dump is basically a backup.
The database is a place to store various data.
The data may be important so that once it is erased, it cannot be restored.
Database dumps are important because the range of impact in the event of a problem is very large and can be serious.
Outputting information such as tables contained in the database in the form of SQL statements is called dumping.
When dumping, the structure of the table and each data stored in the table are output in the form of SQL statements.
When do you use it?
・ Master data (prefectures, cities, wards, towns and villages, etc.)
・ Initial data (user account, etc.)
It is used when using data such as.
The command is as follows.
bin/rake db:seed:dump MODELS=Model name FILE=db/seeds/file name(~.rb)
This is a command to reflect the data of a certain file in the seeds file.
If you want to empty all records, do `` `rake db: reset```.
This will drop all the tables and recreate the tables based on "db / schema.rb".
Another method to reflect from the seeds file to the DB is as follows.
#### **`bundle exec rails r db/seeds/file name(~.rb)`**
```rb)
Please refer to it if you like.
Recommended Posts