简体   繁体   中英

ASP.NET Core Project - Publish doesn't show the “Database Migrations” option

My project used to work perfectly for .NET Core 1.0, but moving to 1.1 is causing me days of headache!! I've been using Microsoft Azure for publishing and hadn't had too many problems.

I think I'm down to just the database migrations. I've been using migrations for quite a while now, but when I publish, I don't get the option to ' Apply this migration on publish '.

I have a second project that's working just fine. When I open up the publishing screen, an icon spins saying ' Discovering Data Contexts... ' and then changes to ' Entity Framework Migrations '.

But for the life of me, I can't get it to work with my main project!!

What could be preventing the 'Entity Framework Migrations' from appearing while publishing?

I've done add-migration Init and update-database and those work perfectly locally, but not when trying to publish

My ApplicationDbContext.cs is just a default, and works with the other project.

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options){
    }

dotnet --info

 .NET Command Line Tools (1.0.0-preview2-1-003177)

And when I run locally, I can delete the SQL Database and Migration puts it back when I start. So I know Migration is working properly. I just can't get the option to show up during publish.

Thanks!!

I've run into the same issue. Unfortunately I don't have an answer yet .

I don't have a specific answer, but I know that it's a known issue for vs2017 RC right now: https://github.com/aspnet/Tooling/blob/master/known-issues-vs2017.md#migrations-not-applied-during-publish

It says to manually apply these migrations, but since I'm using the new project type, I don't have access to the dotnet ef command line tools.

If you have the command line tools available for your project (you're still using project.json and such), then I believe there is a -script option which allows you to output a script for your migration, which you can then run manually on the server.

I've raised an issue on the efcore github here: https://github.com/aspnet/EntityFramework/issues/7276

I just hit this issue, the 'Discovering Data Contexts...' spinner ran for a bit and then I didn't get the 'Entity Framework Migrations' option at all.

What fixed it for me was recreating the publish profile as follows:

From the Publish screen press the Create new profile link: 发布到 Azure 屏幕

And then change to the Select Existing option:

发布 选择现有

Then pick your existing App Service

在此处输入图片说明

Once I did that, the 'Entity Framework Migrations' section showed up as expected in the Publish tool's Settings.

For info, recreating the publishing file doesn't seem to have made any major changes in the .pubmxl file. The only changes were resourcegroups was changed to resourceGroups in the <ResourceId> setting, and <PublishFramework /> was changed to <PublishFramework></PublishFramework> . Neither of those seem likely to be the cause of the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM