Um: ```CommandBox> migrate up Migrating: 2000_0...
# box-products
o
Um:
Copy code
CommandBox> 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?
Schemas:
2000_01_01_000000_create_users_table.cfc
Copy code
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
Copy code
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
Copy code
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" );
	}

}
b
It would appear it is not possible to add the foreign key constraint you asked for.
You'll need to consult your current DB schema and the documentation for your DB. The migrations library is simply the bearer of the error message in this case.
Perhaps if you do a test run of that same SQL in the MySQL workbench, you'll get a more description error message.