ProNotion
02/04/2025, 8:59 AMMigrationBase
and is silently failing with the following exception:
Umbraco.Cms.Infrastructure.Migrations.IncompleteMigrationExpressionException: Cannot create a new expression: the previous expression has not run.
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.BeginBuild[T](T builder)
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Create()
It's occuring here where I try and create the table:
protected override void Migrate()
{
if (!TableExists("MyCustomTable"))
{
Create.Table<MyCustomTable>().Do();
}
}
From what I can gather the error occurs because migrations need to execute each expression before starting a new one but there are no other expressions and I'm struggling to try and find what/where this might be coming from.
Any ideas?Jemayn
02/04/2025, 9:08 AMProNotion
02/04/2025, 9:20 AMpublic class PreLaunchMigrationPlan : MigrationPlan
{
public PreLaunchMigrationPlan() : base("PreLaunchMigrationPlan")
{
From(string.Empty)
.To<CreateCustomTable>("ciwf-0");
}
}
public class PreLaunchMigrationComponent: INotificationHandler<UmbracoApplicationStartedNotification>
{
private readonly IMigrationPlanExecutor _migrationPlanExecutor;
private readonly ICoreScopeProvider _coreScopeProvider;
private readonly IKeyValueService _keyValueService;
private readonly IRuntimeState _runtimeState;
public PreLaunchMigrationComponent(
ICoreScopeProvider coreScopeProvider,
IMigrationPlanExecutor migrationPlanExecutor,
IKeyValueService keyValueService,
IRuntimeState runtimeState)
{
_migrationPlanExecutor = migrationPlanExecutor;
_coreScopeProvider = coreScopeProvider;
_keyValueService = keyValueService;
_runtimeState = runtimeState;
}
public void Handle(UmbracoApplicationStartedNotification notification)
{
if (_runtimeState.Level < RuntimeLevel.Run)
{
return;
}
var migrationPlan = new PreLaunchMigrationPlan();
var upgrader = new Upgrader(migrationPlan);
upgrader.Execute(_migrationPlanExecutor, _coreScopeProvider, _keyValueService);
}
}
Jemayn
02/04/2025, 9:27 AMUmbracoApplicationStartingNotification
and you are using the UmbracoApplicationStartedNotification
but dont know if that mattersProNotion
02/04/2025, 9:28 AMJemayn
02/04/2025, 9:36 AMProNotion
02/04/2025, 9:55 AMJemayn
02/04/2025, 9:56 AMProNotion
02/04/2025, 9:58 AMSebastiaan
02/04/2025, 10:37 AMProNotion
02/04/2025, 10:39 AMProNotion
02/04/2025, 10:41 AMSebastiaan
02/04/2025, 10:41 AMSebastiaan
02/04/2025, 10:41 AMProNotion
02/04/2025, 10:41 AMProNotion
02/04/2025, 10:42 AMProNotion
02/04/2025, 10:43 AMProNotion
02/04/2025, 10:46 AMMigrate()
executes and before I even attempt to create the table I can see that Context.BuildingExpression
is true - the question is why as that is what is causing this to fail.Sebastiaan
02/04/2025, 10:54 AMProNotion
02/04/2025, 10:59 AMProNotion
02/04/2025, 11:00 AMMigrationPlan
ProNotion
02/04/2025, 11:00 AMSebastiaan
02/04/2025, 11:02 AM-
in. Yes this is 13.6
https://cdn.discordapp.com/attachments/1336259761464803328/1336290698722545726/image.png?ex=67a34531&is=67a1f3b1&hm=6dff92798e8348d29143da117d97b7da1c5cda2ae42c544c0c0777d18ef2671e&Sebastiaan
02/04/2025, 11:03 AMSebastiaan
02/04/2025, 11:04 AMProNotion
02/04/2025, 11:04 AMSebastiaan
02/04/2025, 11:05 AMcsharp
From(string.Empty)
.To<CreateCustomTable>("ciwf-0");
ProNotion
02/04/2025, 11:06 AMSebastiaan
02/04/2025, 11:07 AMCreate.Table<BlogCommentSchema>().Do();
- this didn't work as dashes are not allowed in SQLite table names, not sure if full-fat SQL allows those though.ProNotion
02/04/2025, 11:08 AMProNotion
02/04/2025, 11:10 AMSebastiaan
02/04/2025, 11:14 AMManado..
codeProNotion
02/04/2025, 11:17 AM[TableName("ciwfMandatoryProperties")]
[PrimaryKey("Id", AutoIncrement = false)]
[ExplicitColumns]
public class MandatoryPropertyRecord
{
[PrimaryKeyColumn(AutoIncrement = false)]
public Guid Id { get; set; } = Guid.NewGuid(); // Unique identifier
[ForeignKey(typeof(Umbraco.Cms.Core.Models.ContentType))]
public Guid ContentTypeKey { get; set; } // ContentType key
[Column("contentTypeAlias")]
[Length(255)]
public string ContentTypeAlias { get; set; } // ContentType alias
[Column("propertyAlias")]
[Length(255)]
public string PropertyAlias { get; set; } // Alias of the property
[Column("mandatorySetting")]
public bool MandatorySetting { get; set; } // Stores the original mandatory setting
[Column("recordedAt")]
public DateTime RecordedAt { get; set; } = DateTime.UtcNow; // Timestamp of when the setting was backed up
}
However, I'm not convinced it is thatSebastiaan
02/04/2025, 11:21 AMProNotion
02/04/2025, 11:23 AMCreateCustomTable
?Sebastiaan
02/04/2025, 11:23 AMSebastiaan
02/04/2025, 11:24 AMciwfMandatoryProperties
is not ciwf-0
I mean, your previous code examples were for ciwf-0
as a table nameProNotion
02/04/2025, 11:25 AMciwf-0
is not the table name it's the state that s inserted in the umbracoKeyValue
tableSebastiaan
02/04/2025, 11:28 AMciwfMandatoryProperties
and remove [ForeignKey(typeof(Umbraco.Cms.Core.Models.ContentType))]
it works - guess in your example it's trying to instantiate that class which it can't at this point of the boot processProNotion
02/04/2025, 11:29 AMProNotion
02/04/2025, 11:35 AMat Umbraco.Cms.Infrastructure.Migrations.MigrationBase.BeginBuild[T](T builder)
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Create()
at CIWF.Migrations.Migrations.CreateMandatoryPropertiesTable.Migrate() in D:\Repositories\ciwf\src\CIWF.Migrations\Migrations\CreateMandatoryPropertiesTable.cs:line 37
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.Run()
at Umbraco.Cms.Infrastructure.Migrations.MigrationPlanExecutor.RunMigration(Type migrationType, MigrationContext context)
at Umbraco.Cms.Infrastructure.Migrations.MigrationPlanExecutor.RunScopedMigration(Type migrationType, MigrationPlan plan)
at Umbraco.Cms.Infrastructure.Migrations.MigrationPlanExecutor.RunMigrationPlan(MigrationPlan plan, String fromState)
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Alter()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Create()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Delete()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Execute()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Insert()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Rename()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Update()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Alter()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Create()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Delete()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Execute()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Insert()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Rename()
at Umbraco.Cms.Infrastructure.Migrations.MigrationBase.get_Update()
There is still an incomplete expression preventing the Create table method from executingProNotion
02/04/2025, 11:36 AMProNotion
02/04/2025, 11:36 AMSebastiaan
02/04/2025, 11:49 AMUmbracoApplicationStartingNotification
and you might still be relying on Started
.ProNotion
02/04/2025, 12:27 PMUmbracoApplicationStartingNotification
- I tried bothProNotion
02/04/2025, 12:27 PMLuuk Peters (ProudNerds)
02/04/2025, 2:00 PMcsharp
public class DatabaseCreateMigration : INotificationAsyncHandler<UmbracoApplicationStartedNotification>
{
...
public async Task HandleAsync(UmbracoApplicationStartedNotification notification, CancellationToken cancellationToken)
{
var pendingMigrations = await _dbContext.Database.GetPendingMigrationsAsync(cancellationToken);
if (pendingMigrations.Any())
await _dbContext.Database.MigrateAsync(cancellationToken);
}
}
ProNotion
02/05/2025, 12:43 PM