New to coldbox - Having issue with migration

Doing the zero to hero course, I ran the migrate install command and it created the cfmigrations table in my DB. Next doing migrate up it fails because it is trying to create the cfmigrations table again but it already exists. I deleted the table and tried migrate up again but it still says it exists. Running migrate refresh yields database reset but then errors out because the cfmigrations table already exists in the DB.

Is there something else to this I can check? Not sure why it is stuck trying to create that table again or not seeing the one that is there.

I am using Lucee with SQL server 2016.

Thanks! Any help is appreciated.

1 Like

I ended up reloading the terminal/ reading the env again and it got past that step! Now my next issue. A syntax error in my migration file. I’ve been over and over this but can’t find the issue. Any thoughts? It says incorrect syntax by ‘Users’

component {
    
    function up( schema, qb ) {
        queryExecute( "
            CREATE TABLE 'users' (
               'id' INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
               'email' VARCHAR(255) NOT NULL UNIQUE,
               'password' VARCHAR(255) NOT NULL,
               'createdDate' TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
               'modifiedDate' TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
               'role' INTEGER DEFAULT 0,
                CONSTRAINT 'pk_users_id' PRIMARY KEY ('id')
            )
        " );
    }

    function down( schema, qb ) {
         queryExecute( "DROP TABLE 'users'" );
    }

}

1 Like

Hi @Chris_Stewart this is the url to the section if it helps, https://github.com/Ortus-Solutions/cfcasts-coldbox-zero-to-hero/blob/master/step04.md, i did that course a while back and i was looking at my old training projects and i always used the schema with qb version.

component {

    function up( schema, qb ) {
        schema.create( "users", function( table ) {
			table.increments( "id" );
			table.string( "username" ).unique();
			table.string( "email" ).unique();
			table.string( "password" );
			table.timestamp( "createdDate" );
			table.timestamp( "modifiedDate" );
		} );
    }

    function down( schema, qb ) {
        schema.drop( "users" );
    }

}

hope this helps

1 Like

Interesting. Thanks! That worked. On to the next part now.

1 Like

@Chris_Stewart try with this code the issue might be the single quotes, its better to use backticks

            CREATE TABLE `users` (
                `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
                `username` VARCHAR(255) NOT NULL UNIQUE,
                `email` VARCHAR(255) NOT NULL UNIQUE,
                `password` VARCHAR(255) NOT NULL,
                `createdDate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                `modifiedDate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                `role` INTEGER DEFAULT 0,
                CONSTRAINT `pk_users_id` PRIMARY KEY (`id`)
            )

this is good if you still want to use the queryExecute(…) version :grinning_face_with_smiling_eyes:

2 Likes