you should create your foreign keys after creating the table. like this:
public function up()
{
Schema::enableForeignKeyConstraints();
Schema::create('user', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->uuid('id');
$table->primary('id');
$table->string('class_code');
$table->string('username')->nullable();
$table->string('email_address')->nullable();
$table->uuid('contact_id')->nullable();
$table->uuid('customer_id')->nullable();
$table->char('password_hash', 64)->nullable();
$table->boolean('active')->nullable();
$table->string('remember_token', 100)->nullable();
$table->timestamps();
});
Schema::table('user', function(Blueprint $table) {
$table->foreign('contact_id')->references('id')->on('contact')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('customer_id')->references('id')->on('customer')->onDelete('cascade')->onUpdate('cascade');
});
}
you may however need to ensure the order that your migrations are ran is correct. Therefore you may want your create table function to create nullable foreign keys.
myISAMorINNODB? BecausemyISAMdoesn't support foreign key restraints. - Ron van der Heijden