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

EF Core Migrations Configuration #7407

Closed
cigano opened this issue Jan 13, 2017 · 11 comments
Closed

EF Core Migrations Configuration #7407

cigano opened this issue Jan 13, 2017 · 11 comments

Comments

@cigano
Copy link

cigano commented Jan 13, 2017

I didn't find a way to configure the Migrations like in EF6.

        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
            ContextKey = "MySystem";
        }

Is there something planned in EF Core to replace this feature?

@ekarimi
Copy link

ekarimi commented Jan 13, 2017

Automatic migrations has been removed from EF7 and currently there is no support for this feature. I don't think this one will be a good idea at all !!!
Source control is much simpler now. You can now add migrations without applying previous one to the database.
Use code migrations.

@cigano
Copy link
Author

cigano commented Jan 13, 2017

Source control is much simpler now. You can now add migrations without applying previous one to the database. Use code migrations.

@ekarimi I made considerations regarding explicit migrations here and I don't believe this approach will solve the problems in relational databases in team work.

@bricelam
Copy link
Contributor

Are you looking for something like #3053, or is your scenario different?

@cigano
Copy link
Author

cigano commented Jan 13, 2017

@bricelam I understood the idea, it'll be something like:

PM> Recycle-Database

Some Powershell script updates the Snapshot, drop the database, re-scaffold the initial migration and redo a new database with (probably) the seeding process in the end.

Sounds great, but I believe that the initial code migration should have a default name, to source control purposes.

Please note that this doesn't replace the migrations configuration, as I suggested. It would be great if data loss can be configurable.

@rowanmiller
Copy link
Contributor

Configuration of anything migrations related is now done in OnConfiguring (or Startup.cs for ASP.NET Core), rather than having a separate MigrationsConfiguration class.

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder
        .UseSqlServer(@"Server=.\SQL2016;Database=Test;Trusted_Connection=True;", sqlOptions =>
            sqlOptions.MigrationsAssembly("My.System.Migrations")
                      .MigrationsHistoryTable("_Migrations"));
}

Data loss settings only applied to automatic migrations, since scaffolded ones were never run automatically and you could review them before applying.

@rowanmiller
Copy link
Contributor

I'm going to close this one out, as we have a lengthy discussion going on #6214 and we also have #3053 tracking a simpler approach for iterative development.

@bricelam
Copy link
Contributor

Also, in EF Core, we'll warn during Add-Migration if any scaffolded operation would result in data loss.

@cigano
Copy link
Author

cigano commented Jan 14, 2017

@rowanmiller Can I configure data loss tolerance using this method?

@cigano
Copy link
Author

cigano commented Jan 14, 2017

@bricelam Would be possible to use a parameter like -Force to execute the migration even with the data loss?

@bricelam
Copy link
Contributor

The migrations will always execute. The warning occurs while scaffolding.

EF Core is very extensible since you can customize and replace any service. I'm sure you could serialize the data loss flag in the C# and throw during migrate if it's present.

@cigano
Copy link
Author

cigano commented Jan 16, 2017

@bricelam Okay, I'll dig into the sources and try to implement something.

You mentioned the steps to obtain the differences in other issue. I'll use this as a guide to extend EF Core in some way.

@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

5 participants