Skip to content

Adding foreign key fails. #1918

Open
Open
@dereuromark

Description

@dereuromark

This looks familiar to #1805

        $this->table('districts')
            ->addForeignKey('city_id', 'cities', ['id'], ['delete' => 'SET_NULL'])
            ->update();

The table schema is nullable for that field as per docs

        $this->table('districts')
            ->addColumn('city_id', 'integer', [
                'default' => null,
                'limit' => 10,
                'null' => true,
                'signed' => false,
            ])

and exists already for quite some time in the DB as such. All fields are still null of value. So no "invalid cities.id" could be the cause either.

But running the migration above to add the foreign key fails with:

PDOException: SQLSTATE[HY000]: General error: 1005 Can't create table de_local.#sql-3153_65e4 (errno: 150 "Foreign key constraint is incorrectly formed"

MySQL: 10.0.38-MariaDB-0ubuntu0.16.04.1 - Ubuntu 16.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions