Data Seeding and Custom Migrations
Learn how to seed data and use raw SQL in migrations.
We'll cover the following
Data seeding
Data seeding involves populating the database with initial data. It is useful for the following:
- Providing test data in a development environment.
- Setting up initial data in a development/production environment.
Note: The commands in this lesson generate code and files. Through the terminal, we can navigate to these files by using relevant Linux commands such as
ls
to view a list of files and directories,cd
to change directories, andcat
to view file contents. A SPA widget showing the updated project with the generated files is also available. Also, note that EF Core uses a timestamp within the generated file names. We represent these names withxxx
.
In an earlier lesson, we mentioned that the Tags
table holds a set of categories for the artists’ albums. In this section, we use migrations to provide initial data for this table. One way to achieve this is via the OnModelCreating
method of the context class. We’ll demonstrate using the project below:
Get hands-on with 1400+ tech skills courses.