EntityFramework Database Migration

Source: Internet
Author: User
Tags connectionstrings

Database migration

1:enable-migrations

2:add-migration Student.

3:update-database

Generally executing the above 3 commands will succeed

First step: Delete the folders generated by the Migration command: Migrations folder, regenerate

Step Two: Execute the migration command: add-migration, for example: there is a student entity class (Model) in order to name the specification, we generally perform the migration command as follows

Add-migration Student.

Step three: Execute the enable-migrations-force command

Fourth step: Delete the file with create under the Migrations folder

Fifth step: Execute the enable-migrations command

Sixth step: The same as the second step of executing the command, add-migration Student

Seventh Step: Submit to Database Execution command: update-database

Eighth step: View the steps to execute the Add Table field command: Update-database-verbose

Nineth Step: Recompile the solution because the command we executed was to modify the corresponding database under the Debug/relealse directory, so if the database file in the project is set to

Resource output file, and is set to always overwrite, the database will be overwritten even if the Add field command is executed, so after executing the command successfully copy Debug/relealse

The database file under the directory overwrites the database file in the solution, overwrites or sets it, and sets it to never overwrite the

When using automatic migration, be aware of the startup project, preferably configuring a database connection string connection to the corresponding models Web. config or app. config.

As model in the project "PQCC. Models "must be configured in the Web. config or app. config in the Pqcc.models project:

<connectionStrings>
<add name= "Blogdatabase" connectionstring= "Data source=.;i Nitial catalog=blogdatabase; Uid=sa; pwd=123456;integrated security=true "providername=" System.Data.SqlClient "/></connectionstrings>

After you post to the official site, you need to get the automatically generated statement SQL script. and update the official site database

The syntax is as follows: Update-database-script-sourcemigration 201610030621164_modifyscorereprot

201411240324186_modifyscorereprot represents the current version of the SQL script statement. Corresponds to the Migrationid field in the Dbo.__migrationhistory table

If you post to the official site later, you need to get the automatically generated statement SQL script. and update the official site database to execute the following statement is

Update-database-script-sourcemigration 201610030621164_modifyscorereprot Report the following error:

Unable to update database to match the current model because there be pending changes and automatic migration is disabled . Either write the pending model changes to a code-based migration or enable automatic migration. Set dbmigrationsconfiguration.automaticmigrationsenabled to True to enable automatic migration

The 201610030621164_modifyscorereprot file is not included in your current project migrations file.

In the Dbo.__migrationhistory table, there are 201610030621164_modifyscorereprot records in the Migrationid field. Explain the other classmates who worked with you did not submit the 201610030621164_modifyscorereprot file in the project or the file and was manually deleted. Therefore, it is best to submit all the generated files under the Migrations folder one at a time to SVN is the kingly

EntityFramework Database Migration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.