Ookma-Kyi
11/04/2022, 4:48 PMCommandBox> migrate up
Migrating: 2000_01_01_000000_create_users_table
Migrated: 2000_01_01_000000_create_users_table
Migrating: 2000_01_01_000001_create_belts_table
Migrated: 2000_01_01_000001_create_belts_table
Migrating: 2000_01_01_000002_create_characters_table
ERROR (5.5.2+00578)
Cannot add foreign key constraint
C:\Users\ookma\.CommandBox\cfml\modules\commandbox-migrations\modules\cfmigrations\modules\qb\models\Schema\SchemaBuilder.cfc
CREATE TABLE `characters` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`userid` INTEGER NOT NULL,
`deleted` TINYINT(1) NOT NULL DEFAULT 0,
`active` TINYINT(1) NOT NULL DEFAULT 0,
`name` VARCHAR(25) NOT NULL UNIQUE,
`xp` INTEGER NOT NULL DEFAULT 0,
`belt` INTEGER NOT NULL,
`wins` INTEGER NOT NULL DEFAULT 0,
`loses` INTEGER NOT NULL DEFAULT 0,
`draws` INTEGER NOT NULL DEFAULT 0,
CONSTRAINT `pk_characters_id` PRIMARY KEY (`id`),
CONSTRAINT `fk_characters_userid` FOREIGN KEY (`userid`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT `fk_characters_belt` FOREIGN KEY (`belt`) REFERENCES `belts` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE
)
Um what?Ookma-Kyi
11/04/2022, 4:54 PM2000_01_01_000000_create_users_table.cfc
component {
function up( schema, query ){
schema.create( "users", function(table) {
table.increments( "id" );
table.string( "username", 25 ).unique();
table.string( "email" ).unique();
table.string( "password", 60 );
table.string( "token", 64 ).nullable();
table.datetime( "expiration" ).default( now() );
table.boolean( "notifications" ).default( 0 );
} );
}
function down( schema, query ){
schema.drop( "users" );
}
}
2000_01_01_000001_create_belts_table.cfc
component {
function up( schema, query ){
schema.create( "belts", function(table) {
table.increments( "id" );
table.string( "name", 32 ).unique();
table.string( "image" );
table.integer( "min_xp" );
table.integer( "max_xp" );
} );
}
function down( schema, query ){
schema.drop( "belts" );
}
}
2000_01_01_000002_create_characters_table.cfc
component {
function up( schema, query ){
schema.create( "characters", function(table) {
table.increments( "id" );
table.integer( "userid" ).references( "id" ).onTable( "users" ).onDelete( "cascade" );
table.boolean( "deleted" ).default( 0 );
table.boolean( "active" ).default( 0 );
table.string( "name", 25 ).unique();
table.integer( "xp" ).default( 0 );
table.integer( "belt" ).references( "id" ).onTable( "belts" ).onDelete( "cascade" );
table.integer( "wins" ).default( 0 );
table.integer( "loses" ).default( 0 );
table.integer( "draws" ).default( 0 );
} );
}
function down( schema, query ){
schema.drop( "characters" );
}
}
bdw429s
11/04/2022, 5:17 PMbdw429s
11/04/2022, 5:17 PMbdw429s
11/04/2022, 5:18 PM