jeudi 14 novembre 2019

Laravel change `id` to `AUTO_INCREMENT`

I have a persons table and blogs table. I want to change the id column of persons table to AUTO_INCREMENT.

But it throws an error.

Persons table

id - integer (not auto_increment)
name - string

blogs table

id - integer (auto_increment)
title - string
description - text
created_by - integer (foreign key) 

I created a migration to change id of persons table.

alter user migration

Schema::table('persons', function (Blueprint $table) {
            $table->bigIncrements('id')->change();
        });

I throws an Error

  Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1833 Cannot change column 'id': used in a foreign key constraint 'blogs_created_by_foreign' of table 'db.blogs' (SQL: ALTER TABLE persons CHANGE id id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire