morh
morh

Reputation: 101

Why can't I set auto increment to a field that is used as a foreign key in another table?

I want both id's to auto increment: tables

I get this error when synchronizing the model:

Executing SQL script in server
ERROR: Error 3780: Referencing column 'taskList_id' and referenced column 'id' in foreign key constraint 'fk_task_taskList' are incompatible.
SQL Code:
        ALTER TABLE `easyManage`.`task` 
        ADD CONSTRAINT `fk_task_taskList`
          FOREIGN KEY (`taskList_id`)
          REFERENCES `easyManage`.`taskList` (`id`)
          ON DELETE CASCADE
          ON UPDATE NO ACTION

Upvotes: 0

Views: 245

Answers (2)

marcothesane
marcothesane

Reputation: 6731

Your task.tasklist_id is VARCHAR(55).

And your tasklist.id is an INT.

They should be of the same data type.

And - if you say: "I want both id's to auto increment" - I take it you mean task.id and tasklist.id - and not task.tasklist_id - and then everything should work just fine.

Upvotes: 0

Martin
Martin

Reputation: 36

tasklist_id in table task is varchar(55). It has to be int to hold id from table tasklist

Upvotes: 2

Related Questions