在练习Mvc项目时,提示如下数据库错误:
The model backing the ‘EFDbContext‘ context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
按上述链接要求,在程序包管理控制台执行:Enable-Migrations 后,
生成对应DAL目录内生成 Mirgrations新目录,
再执行 Update-Database, 提示
Specify the ‘-Verbose‘ flag to view the SQL statements being applied to the target database.
No pending explicit migrations.
Unable to update database to match the current model because there are 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.
You can use the Add-Migration command to write the pending model changes to a code-based migration.
项目仍无法连接数据库,
后直接清除数据库内的 [__MigrationHistory]表数据,
问题成功解决。
时间: 2024-10-06 22:18:31