Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet ef migrations error #16

Open
maketochen opened this issue Apr 21, 2023 · 2 comments
Open

dotnet ef migrations error #16

maketochen opened this issue Apr 21, 2023 · 2 comments

Comments

@maketochen
Copy link

请问这个迁移如何操作
cd ModernWMS
dotnet ef migrations add init
Build started...
Build succeeded.
Your target project 'ModernWMS' doesn't match your migrations assembly 'ModernWMS.Core'. Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("ModernWMS")). By default, the migrations assembly is the assembly containing the DbContext.
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.
cd .\ModernWMS.Core
Unable to create an object of type 'SqlDBContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

@JawerZ
Copy link
Contributor

JawerZ commented Apr 25, 2023

报错中已提及,项目的DBContext在ModernWMS.Core下,所以迁移时需要以ModernWMS.Core为目标项目,对应依赖包在Core项目下需要有,不过我看您已经切换使用SQLServer了为何还要做迁移,常用的数据库初始化脚本都已上传至本项目您可以看一下是否有您需要的。

@maketochen
Copy link
Author

该问题已解决,就是在初次迁移的时候 如果数据库已存在表,就是会报错,需要注释掉up方法里的代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants