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
Migration in different assembly than target assembly not supported #5900
Comments
@natemcmaster can you give guidance on this |
@VikSab This is a common error when working with a DbContext that is in a separate project from your web app project. Can you share more details about which projects you are using and the file structure of your code? |
TestWeb.zip |
Thanks for the repro. You will see the error when invoking EF commands on the "Web" project. The exception message you are seeing is by-design. All EF commands have this check:
As the error message suggests, you have have a two options to resolve this 1 - Change target assembly.
2 - Change the migrations assembly. options.UseSqlServer(connection, b => b.MigrationsAssembly("Web")) If you are still getting this error message even after changing either your migration assembly or your target assembly, please feel free to re-open the issue. |
Looks good i was placing the --startup-project on the database command and not the ef command.. the help file doesnt seem to have this option dotnet ef --help --project-dir The folder used as the project directory (defaults to current working directory). --content-root-path The folder used as the content root path for the application (defaults to application base directory). --root-namespace The root namespace of the target project (defaults to the project assembly name). Commands: database Commands to manage your database dbcontext Commands to manage your DbContext types migrations Commands to manage your migrations Use "dotnet ef [command] --help" for more information about a command. |
@VikSab it's there, but the help output doesn't show it. I'm working to fix this in #5188. See https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html for the "true" set of available parameters. |
Should have said - that it works.. - i was trying to apply it - but on the database or update command - didnt try it on the ef command. The help file update would have made the fix easier to self managed thanks |
@natemcmaster could you advise on following:
Earlier those issues can be resolved by storing particular dll and running migrate.exe on them. so the defined migrations in these dlls ran. How could i use dotnet ef on the particular package to do the migrations defined in the particular package? |
@Defee please open a new issue for your question. |
Please Ignore my previous comment I was putting the --startup-project in the wrong place |
Thanks a lot, works for me. |
dotnet ef --startup-project ../XXXX.API migrations add MigrationName -c MyContext |
Below is the command for Package Manager Console (Select YourApp.Data in Target Project dropdown )
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell |
Steps to reproduce
Create Web project that injects and initializes the DbContext and a Models project with the DbContext and migrations
The issue
Your target project '#Target Project#' doesn't match your migrations assembly '#Migrations Assembly#'. Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("#Target Project#")). By default, the migrations assembly is the assembly containing the DbContext.
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 text was updated successfully, but these errors were encountered: