How do you create a composite primary key with Umbraco's Migration system?
I am trying to create a simple table using Umbraco's database migration system, and I can't figure out how to create a table with a composite primary key.
Here's an example of the code I am trying to use:
using Umbraco.Core.Migrations;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using DbConstants = MyProjects.Data.Constants.Database;
namespace MyProjects.Data.Migrations
{
public class _00_Create : MigrationBase
{
public _00_Create( IMigrationContext context ) : base( context ) { }
public override void Migrate()
{
if ( !TableExists( DbConstants.TBL_NAME ) ) {
Create.Table( DbConstants.TBL_NAME )
.WithColumn( "Composite1" )
.AsString( 40 )
.NotNullable()
.PrimaryKey( "PK_Composite1" )
.WithColumn( "Composite2" )
.AsString( 40 )
.NotNullable()
.PrimaryKey("PK_Composite2")
.WithColumn( "DateAdded" )
.AsDateTime()
.WithDefault( SystemMethods.CurrentDateTime )
.WithColumn( "DateUpdated" )
.AsDateTime()
.WithDefault( SystemMethods.CurrentDateTime )
.Do();
}
}
}
}
The above is only an example of what I'm trying to do, hence the rubbish column naming.
I am aware that there's a way to pass a type into the Create.Table method instead, but I have read that it's inadvisable to use that method with migrations.
Is someone able to explain how to create such a table using Umbraco Migrations?
How do you create a composite primary key with Umbraco's Migration system?
I am trying to create a simple table using Umbraco's database migration system, and I can't figure out how to create a table with a composite primary key.
Here's an example of the code I am trying to use:
The above is only an example of what I'm trying to do, hence the rubbish column naming.
I am aware that there's a way to pass a type into the Create.Table method instead, but I have read that it's inadvisable to use that method with migrations.
Is someone able to explain how to create such a table using Umbraco Migrations?
Thanks
Sorry to bump this, but I still haven't figured it out.
Could anyone advise?
Thanks
is working on a reply...