Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MariaDB] Can't run migrations with foreign key constraints (SQLSTATE[HY000]: General error: 1025 Error on rename) #2522

Closed
rzubov-devpro opened this issue Feb 27, 2020 · 4 comments

Comments

@rzubov-devpro
Copy link

rzubov-devpro commented Feb 27, 2020

Description:

php artisan migrate command fails for MariaDB, but working fine for MySQL.
I'd tried to migrate from MySQL to MariaDB and I stuck because I can't execute Laravel migrations.

Each migration contains code like

    Schema::create('articles', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');

            $table->foreign('user_id')
                ->references('id')
                ->on('users')
                ->onDelete('cascade');
        });

Fails with error like
SQLSTATE[HY000]: General error: 1025 Error on rename of './db/articles' to './db/#sql2-1-11c' (errno: 168 "Unknown (generic) error from engine") (SQL: alter table `articles` add constraint `articles_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade)

This can be fixed by wrapping all the code above with:

 Schema::disableForeignKeyConstraints();
// all the code above
 Schema::enableForeignKeyConstraints();

which is not so good, but something.

But in the next migration file, I have a code like

Schema::create('article_tag', function (Blueprint $table) {
            $table->unsignedBigInteger('article_id');
            $table->unsignedBigInteger('tag_id');

            $table->primary(['article_id', 'tag_id']);

            $table->foreign('article_id')
                ->references('id')
                ->on('articles')
                ->onDelete('cascade');

            $table->foreign('tag_id')
                ->references('id')
                ->on('tags')
                ->onDelete('cascade');
        });

Which fails with a different error
SQLSTATE[HY000] [2002] Connection refused (SQL: alter table `article_tag` add primary key `article_tag_article_id_tag_id_primary`(`article_id`, `tag_id`))

And laradock_mariadb_1 container crashes and I have to remove .laradock/data/mariadb folder to get it working again

Expected Behavior:

Alter SQL queries for MariaDB working as expected, the same as for MySQL, so that it's possible to use MariaDB

Context information:

Output of git rev-parse HEAD

c670d5f98b88aedae8fff4db77790203c0a9cbca

Output of docker version

Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:22:37 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:29:19 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker-compose version

docker-compose version 1.25.4, build 8d51620a
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.1c  28 May 2019

System info: Mac, Windows or Linux. Include which disto/version

Windows 10

Steps to reproduce the issue:

  1. Create a project based on laradock + Laravel 6.2 with MySQL DB
  2. Change DB_HOST to mariadb, change PMA_DB_ENGINE to mariadb
    3. docker-compose up -d nginx mariadb phpmyadmin
  3. create db using artisan command or using PhpMyAdmin
  4. php artisan migrate

Stacktrace & Additional info:

1) **Laravel version**: 6.2
2) The same behavior if I run queries using PhpMyAdmin
3) MariaDB image version 10.4.12, also tried next versions: 10.1, 10.2, 10.5.1-bionic
4) logs

laradock_mariadb_1.log
laradock_mariadb_1_rename.log

@bestlong
Copy link
Member

bestlong commented Mar 2, 2020

SQLSTATE[HY000] [2002] Connection refused

run docker-compose logs mariadb check db log

@rzubov-devpro
Copy link
Author

rzubov-devpro commented Mar 3, 2020

@bestlong Please find a log
laradock_mariadb_1.log

There is another log for foreign key constraint:
laradock_mariadb_1_rename.log

@rzubov-devpro
Copy link
Author

Might be related to docker/for-win#5604

@rzubov-devpro
Copy link
Author

My issue has been resolved with Docker upgrade to 2.2.0.4 version, so I'll close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants