users.id and posts.author_id column types should match. Change $table->unsignedInteger('author_id'); to $table->unsignedBigInteger('author_id');
Sep 7, 2019
7
Level 2
Moving a project from Windows to a Linux enviroment
I recently installed ubuntu and cloned my laravel project from github to work with in my ubuntu enviroment. I set up the LAMP stack according to this digital ocean guide https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04 . But now when I want to run migrations I get the error saying:
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `posts` add constraint `posts_author_id_foreign` foreign key (`author_id`) references `users` (`id`) on delete cascade)
I check the exact project back in my windows enviroment (wamp) and all the migrations go through smoothly.
Users migration example:
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
});
Posts migration example:
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('author_id');
$table->foreign('author_id')->references('id')->on('users')->onDelete('cascade');
});
Level 53
1 like
Please or to participate in this conversation.