So I have a ton of migration files like this that work and apply their changes when I start the application locally no problem whatsoever.
I also have defined my connection strings and database name and have quadruple checked it's right. But when I go to deploy the webapplication on the server the database isn't created, the migrations aren't applied. I figured that when the application was running on the server that the database would just be created by the application.
What am I missing?
Example migration file:
using Microsoft.EntityFrameworkCore.Migrations;
namespace Persistence.Migrations
{
public partial class modificationstoprivsandroles : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Name",
table: "UserRoles");
migrationBuilder.DropColumn(
name: "Name",
table: "Tags");
migrationBuilder.DropColumn(
name: "Name",
table: "Privileges");
migrationBuilder.AddColumn<int>(
name: "Type",
table: "UserRoles",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "Type",
table: "Tags",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "Type",
table: "Privileges",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Type",
table: "UserRoles");
migrationBuilder.DropColumn(
name: "Type",
table: "Tags");
migrationBuilder.DropColumn(
name: "Type",
table: "Privileges");
migrationBuilder.AddColumn<string>(
name: "Name",
table: "UserRoles",
type: "longtext CHARACTER SET utf8mb4",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Name",
table: "Tags",
type: "longtext CHARACTER SET utf8mb4",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Name",
table: "Privileges",
type: "longtext CHARACTER SET utf8mb4",
nullable: true);
}
}
}
Data Context
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//modelBuilder.Model.SetMaxIdentifierLength(30);
////Attempt 1:
////https://stackoverflow.com/questions/58821587/pomelo-entityframeworkcore-mysql-error-with-ef-core-3-0
//modelBuilder.Entity<AppUser>(entity => entity.Property(m => m.Id).HasMaxLength(255));
////Other attempt.
////modelBuilder.Entity<HistoryRow>().Property(h => h.MigrationId).HasMaxLength(100).IsRequired();
////modelBuilder.Entity<HistoryRow>().Property(h => h.ContextKey).HasMaxLength(200).IsRequired();
////https://stackoverflow.com/questions/20832546/entity-framework-with-mysql-and-migrations-failing-because-max-key-length-is-76
modelBuilder.Entity<Value>().HasData(
new Value { Id = 1, Name = "Value 1331" },
new Value { Id = 2, Name = "Value 1332" },
new Value { Id = 3, Name = "Value 1333" }
);
...
Even have a Seed Data file.
namespace Persistence
{
public class Seed
{
public static async Task SeedData(DataContext context,
UserManager<AppUser> userManager)
{
if (!context.Privileges.Any())
{
var privileges = new List<Privilege>
{
new Privilege
{
Id = Guid.Parse("11e36cdd-b1a0-489b-ad79-9e926eece529"),
Type = Privilege.PrivilegeTypes.ADMIN,
Description = "Administrator role"
}
};
await context.Privileges.AddRangeAsync(privileges);
await context.SaveChangesAsync();
}
...
Really not sure why the database isn't just kicking in here.