创建表时,外键约束的格式不正确

时间:2019-01-15 18:56:43

标签: mysql sql phpmyadmin

我有两个SQL查询,当我编写第二个查询时,它会丢弃一个SQL错误,例如“外键约束格式不正确”。而且我不知道,第一个表的ID具有主键。

CREATE TABLE clients(
    id_client INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(32),
    surname VARCHAR(32),
    dni VARCHAR(32),
    address VARCHAR(32),
    type CHAR
)

另外一个:

CREATE TABLE clients_vehicles(
    id_client_vehicle INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    license_plate VARCHAR(32),
    num_chasis VARCHAR(32),
    color VARCHAR(32),
    brand VARCHAR(32),
    model VARCHAR(32),
    model_version VARCHAR(32),
    fuel_type CHAR,
    km INT,
    cv INT,
    type CHAR,
    id_client INT NOT NULL,
    FOREIGN KEY (id_client) REFERENCES clients(id_client)
)

1 个答案:

答案 0 :(得分:1)

clients_vehicles.id_clientINT,而clients.id_clientUNSIGNED INT。类型不匹配。

UNSIGNED INT更改为INT,它将起作用