Add migration
let's add a migration
Let us add migration to include the vehicle type as well. Before running the below command, make sure you have saved all the files and the application compiles successfully.
Notice the generated code in migration file
Notice the following
A new table is being created in the name of Vehicles
it has the required columns along with appropriate data types
primary key for the vehicles table is Id column as usual
StudentId is made a foreign key to Students table
EF has identified the principal table and the principal column as Students and Id respectively
Delete cascade is the default action, we can configure it otherwise
As expected, there is no change to the Students table
let us apply the migration
Now that we have verified that the migration code generated is appropriate and matches our domain requirements, let us go ahead and apply it so that the necessary changes are made in the database
We should now see the new table created in our database
Last updated