-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 does not work properly #1062
Comments
You could make it conditional by passing an arg when starting the app: if (app.Environment.IsDevelopment() && args.Contains("--init"))
{
await app.InitialiseDatabaseAsync();
} Then you should be able to run it using: dotnet run --init This will allow for a dev to remove a migration and allow them to choose when they want to initialise the app. |
I think this is not perfect solution when you run app directly from Visual Studio instead of Command Line |
You shouldnt need to seed your db every time you run your app. |
I found issue and resolved this. if (app.Environment.IsDevelopment())
{
var lineArgs = Environment.GetCommandLineArgs();
if(!lineArgs.Any(p => p.Contains("NSwag.AspNetCore.Launcher.dll")))
{
await app.InitialiseDatabaseAsync();
}
} |
Describe the bug
When I use any migrations command, the last pending migration migrate automatically. This cause I can't remove last migrations.
To Reproduce
Steps to reproduce the behavior:
1./ Create new project using dotnet template
2./ Modify any entity in domain
public class TodoList : BaseAuditableEntity { public string? Title { get; set; } public Colour Colour { get; set; } = Colour.White; + public string? Descriptions { get; set; } public IList<TodoItem> Items { get; private set; } = new List<TodoItem>(); }
3./ Add next migration without runing application
4./ Don't run application then check database
00000000000000_InitialCreate
migrations applied (wrong from here)5./ Modify something next
public class TodoList : BaseAuditableEntity { public string? Title { get; set; } public Colour Colour { get; set; } = Colour.White; public string? Descriptions { get; set; } + public string? Descriptions2 { get; set; } public IList<TodoItem> Items { get; private set; } = new List<TodoItem>(); }
6./ Add next migration without runing application
7./ Don't run application then check database
*********_Migration1AfterInit
migrations applied (wrong here too)8./ Remove last migration (wrong here too)
got errors
The migration '***********_Migration2AfterInit' has already been applied to the database. Revert it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration instead.
Additional context
Comment this code in
Program.cs
atWeb
Project, everything work perfectly, but we can't seed dataand I tried but not work
Expected behavior
Ef migration feature work properly with seed data.
The text was updated successfully, but these errors were encountered: