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

Migrations: Using name with Script-Migration doesn't work (only ID) #6228

Closed
warrior1305 opened this issue Aug 2, 2016 · 4 comments
Closed
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@warrior1305
Copy link

I use Entity Framework Core and PostgreSQL

project.json

{
    "authors": [ "sam" ],
    "buildOptions": {
        "emitEntryPoint": "true"
    },
    "dependencies": {
        "Microsoft.EntityFrameworkCore": "1.0.0",
        "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",

        "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.1",
        "Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.1",

        "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",

        "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",

        "Microsoft.Extensions.Configuration.Abstractions": "1.0.0",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",

        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",

        "DelegateDecompiler": "0.18.1",
        "DelegateDecompiler.EntityFramework": "0.18.1",
    },
    "description": "Xrm.Hcs.DataLayer Class Library",
    "frameworks": {
        "net451": {
            "frameworkAssemblies": {
                "Microsoft.CSharp": "4.0.0.0",
                "System.Collections": "4.0.0.0",
                "System.Linq": "4.0.0.0",
                "System.Threading": "4.0.0.0",
                "System.Runtime": "4.0.10.0",
                "System.ComponentModel.DataAnnotations": "4.0.0.0",
                "System.Data": "4.0.0.0",
                "System.Transactions": "4.0.0.0"
            }
        }
    },
    "tools": {
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
    },
    "version": "1.0.0-*"
}

Startup.cs

       public void ConfigureServices(IServiceCollection services)
       {
            services.AddDbContext<MyContext>(options => options.UseNpgsql(Configuration["ConnectionStrings:PgSqlServer"]));
        }

MyContext.cs

    public class HcsContext : DbContext
    {
        public HcsContext(DbContextOptions<HcsContext> contextOptions) : base(contextOptions)
        {
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            // some configs
            foreach (var fk in modelBuilder.Model.GetEntityTypes().SelectMany(x=>x.GetForeignKeys()))
            {
                fk.DeleteBehavior = DeleteBehavior.Restrict;
            }
        }
    }

When I run command:
dotnet ef migrations script V038Migration V039Migration -o Migrations/Sql.Up/migration_v038_to_v039.sql
everything is okay: there are no errors. When command finished, it returns "Done".
But migration_v038_to_v039.sql is empty.
If I generate *.cs class with migration code - it is not empty (and it has code i expected)

But if I run next command:
dotnet ef migrations script V039Migration V038Migration -o Migrations/Sql.Down/migration_v039_to_v038.sql
then migration_v039_to_v038.sql will be not empty

@divega
Copy link
Contributor

divega commented Aug 2, 2016

@warrior1305 is your model really empty as shown in the empty DbContext? If it isn't, can you provide it?

@warrior1305
Copy link
Author

warrior1305 commented Aug 3, 2016

I found solution of my problem:
for creating up scripts I should run:
dotnet ef migrations script 20160803073244_V038Migration 20160728115142_V037Migration

But for genering down scripts I should run:
dotnet ef migrations script V038Migration V037Migration //without timestamp

But this don't make me happy, because up scripts are not right: they duplicate sql code.
Example:
When I create scripts from v001 to v002, in 001_002.sql I have up script from v001.cs and v002.cs
When I create scripts from v002 to v003, in 002_003.sql I have up script from v002.cs and v003.cs

There is my test project with generated migrations:
DataLayerTest.zip

@bricelam bricelam removed this from the 1.1.0 milestone Aug 9, 2016
@bricelam
Copy link
Contributor

bricelam commented Aug 9, 2016

Oops, I just commented on the wrong issue. Sorry, @warrior1305.
(Removing comments...)

@bricelam bricelam added this to the 1.1.0 milestone Aug 9, 2016
@bricelam bricelam changed the title dotnet-ef-migrations-script don't generate up script Migrations: Using name with Script-Migration doesn't work (only Id) Aug 9, 2016
@bricelam bricelam removed this from the 1.1.0 milestone Aug 9, 2016
@bricelam
Copy link
Contributor

bricelam commented Aug 9, 2016

This has regressed at some point. Both migration names and ids should be supported. This is particularly bad because PowerShell will expand the name, not the id.

@bricelam bricelam changed the title Migrations: Using name with Script-Migration doesn't work (only Id) Migrations: Using name with Script-Migration doesn't work (only ID) Aug 9, 2016
@divega divega added this to the 1.0.1 milestone Aug 10, 2016
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants