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

In RC2 how to update database on product. #5509

Closed
chinaq opened this issue May 25, 2016 · 5 comments
Closed

In RC2 how to update database on product. #5509

chinaq opened this issue May 25, 2016 · 5 comments

Comments

@chinaq
Copy link

chinaq commented May 25, 2016

The issue

In RC1 when I published a website, it generated a ef.cmd file, I can ran ef database update to update the product database. How can I do it in RC2 when there is no ef.cmd file.

@leak
Copy link

leak commented May 25, 2016

@rowanmiller
Copy link
Contributor

@chinaq are you using the right-click->Publish... functionality in Visual Studio? If so, there is a checkbox in the wizard to apply migrations to the target database during deployment (new in RC2).

@chinaq
Copy link
Author

chinaq commented May 26, 2016

Thanks @rowanmiller. I published by the wizard to apply migrations to the target database, but it comes another problem. Because my website and the repo are in different projects and assembles, it causes

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error : Your target project 'SofuProdContr.BE.WebApi' doesn't match your migrations assembly 'SofuProdContr.BE.Repo2'. Either change your target project or change your migrations assembly.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error : Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("SofuProdContr.BE.WebApi")). By default, the migrations assembly is the assembly containing the DbContext.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error : 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.

The context is in the repo assemble SofuProdContr.BE.Repo2, and I have to change the target to SofuProdContr.BE.Repo2. But When publishing I can not execute donnet ef manually.

How can I solve this?Thanks.

@leak
Copy link

leak commented May 26, 2016

You probably have to wait until #5320 will be resolved.

@rowanmiller
Copy link
Contributor

@leak is correct, this is due to #5320 which is a limitation we are working to remove for the next release.

In the meantime, the best workaround is to revert to applying migrations in Startup.cs. You would do that by putting code like this in the Configure(...) method.

using (var context = new MyContext(app.ApplicationServices.GetRequiredService<DbContextOptions<MyContext>>()))  
{  
    context.Database.Migrate();  
}  

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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

4 participants