Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikocevicstefan's avatar

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');
});
0 likes
7 replies
Sti3bas's avatar
Sti3bas
Best Answer
Level 53

users.id and posts.author_id column types should match. Change $table->unsignedInteger('author_id'); to $table->unsignedBigInteger('author_id');

1 like
Sti3bas's avatar

@nikocevicstefan it's failing at database level, so operating system should not affect this. Do you use the same database management system on both OSes?

Sti3bas's avatar

I have no clue then, but I hope the first comment solved your issue on Linux.

Please or to participate in this conversation.