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 being generated for a context that I don't want #42

Closed
armille3 opened this issue May 3, 2017 · 13 comments
Closed

Migrations being generated for a context that I don't want #42

armille3 opened this issue May 3, 2017 · 13 comments
Labels

Comments

@armille3
Copy link

armille3 commented May 3, 2017

I am running the following command:
dotnet ef migrations add "CatchUp" -c DrsDbContext
However, when I look at the "CatchUp" migration, it is generating code that is using the EdwDbContext, which I do not want.

@mrahhal
Copy link
Owner

mrahhal commented May 4, 2017

Seems there's a bug (it should be giving you an error though). But anyway, you need to enable migrations for your DbContext before calling "migrations add". But the "migrations enable" command is faulty it seems, it does not accept a context. Will fix this soon.

@mrahhal
Copy link
Owner

mrahhal commented May 4, 2017

Should be fixed in 1.1.3. Please let me know if you face the issue again.

Note that if you want to work with migrations for more than one context you should specify and output directory for each:

dotnet ef migrations add "CatchUp" -c DrsDbContext -o Migrations2

It's very important that migrations from different contexts live in different folders and different namespaces.

@mrahhal mrahhal closed this as completed May 4, 2017
@mrahhal mrahhal added the bug label May 4, 2017
@armille3
Copy link
Author

armille3 commented May 4, 2017

I updated, did a complete clean, dotnet restore, and deleted all my migrations folders. I then called these commands:
dotnet ef migrations enable -c DrsDbContext -o Migrations

dotnet ef migrations enable -c EdwDbContext -o EdwMigrations

dotnet ef migrations add InitialCreate -c DrsDbContext -o Migrations

dotnet ef migrations add InitialCreate -c EdwDbContext -o EdwMigrations

However still in EdwMigrations everything from DrsDbContext is there, and in Migrations, everything from EdwDbContext is there.

@mrahhal
Copy link
Owner

mrahhal commented May 4, 2017

Sorry, will give this some time soon and try it with a project from scratch. I tested it really fast and it seemed to be working 🏃 😅

@mrahhal
Copy link
Owner

mrahhal commented May 4, 2017

@armille3 tried doing the exact same commands in your last comment in a new project and it worked. Can you provide a repro if you're sure you're still experiencing the same issue?

@armille3
Copy link
Author

armille3 commented May 4, 2017

See attached for a simplified example of my project with this problem. The connection string will need changed in Drs.Framework.Repositories.CoreApiInitializer.

Drs.zip

@mrahhal
Copy link
Owner

mrahhal commented May 4, 2017

Just tested it, and yeah the problem occurs. Maybe it's the way you're structuring the files. I'll investigate more.

@mrahhal
Copy link
Owner

mrahhal commented May 5, 2017

@armille3 I tried hard to reproduce the problem from a new project but I couldn't. Tried putting all the models in the root namespace, and still worked. The problem is only happening in the project you sent. Not sure what I can do at this point since your project is too complex to figure out what's happening.

If you can reproduce this in a minimal simple project I might be able to help.

@armille3
Copy link
Author

armille3 commented May 5, 2017

I noticed that if I give it a fake DbContext name, it continues anyways without a warning. For example:

dotnet ef migrations enable -c asdf

I am going through your code trying to find anything.

@armille3
Copy link
Author

I ended up getting around this by placing my other context in another project. What I think is causing this however is the mappings. I'm guessing if I delete the mappings from the other context in the project, it would work fine.

@mrahhal
Copy link
Owner

mrahhal commented May 10, 2017

The mappings?

In any case, good to hear you got around it.

@armille3
Copy link
Author

Yeah, the EntityTypeConfigurations. You can do this either by attributes, or how I do it via a mapping class.

 internal class EdwEmployeeMapping : EntityTypeConfiguration<Core.EdwEmployee.EdwEmployee>
    {
        public EdwEmployeeMapping()
        {
            ToTable("EdwEmployees");
            HasKey(x => x.EdwPersonId);
            Property(x => x.EdwPersonId).HasColumnName("EDW_PERS_ID");
            Property(x => x.Active).HasColumnName("PERS_CUR_INFO_IND");
            Property(x => x.Uin).HasColumnName("UIN");
            Property(x => x.Confidentiality).HasColumnName("PERS_CONFIDENTIALITY_IND");
            Property(x => x.FirstName).HasColumnName("PERS_FNAME");
            Property(x => x.MiddleName).HasColumnName("PERS_MNAME");
            Property(x => x.LastName).HasColumnName("PERS_LNAME");
            Property(x => x.Suffix).HasColumnName("PERS_NAME_SUFFIX");
            Property(x => x.PrefferredFirstName).HasColumnName("PERS_PREFERRED_FNAME");
        }
    }

@mrahhal
Copy link
Owner

mrahhal commented May 10, 2017

Oh. Hmm, can't see how this might be a problem for "Migrator.EF6" itself. I'm not doing anything special here. But I'll investigate a bit more when I have some time.

Thanks!

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

No branches or pull requests

2 participants