开发者

Mysql: ERROR 1005 (HY000): Can't create table 'receitascakephp.recipes' (errno: 150)

开发者 https://www.devze.com 2023-01-05 08:37 出处:网络
CREATE TABLE `users` ( `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT, `name` VARCHA开发者_如何学CR(255) NOT NULL,
CREATE TABLE `users` (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHA开发者_如何学CR(255) NOT NULL,
    `username` VARCHAR(75) NOT NULL,
    `password` VARCHAR(75) NOT NULL,
    `image` VARCHAR(255)
);

CREATE TABLE `recipes` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `name` VARCHAR(255) NOT NULL,
    `method` TEXT NOT NULL,
    `image` VARCHAR(255),
    `user_id` INT NOT NULL,
    CONSTRAINT `fk_recipes_users` FOREIGN KEY(`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I don't know why, but I'm getting:

ERROR 1005 (HY000): Can't create table 'receitascakephp.recipes' (errno: 150)


Both tables need to be InnoDB:

CREATE TABLE `users` (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
    `username` VARCHAR(75) NOT NULL,
    `password` VARCHAR(75) NOT NULL,
    `image` VARCHAR(255)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `recipes` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `name` VARCHAR(255) NOT NULL,
    `method` TEXT NOT NULL,
    `image` VARCHAR(255),
    `user_id` INT NOT NULL,
    CONSTRAINT `fk_recipes_users` FOREIGN KEY(`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
0

精彩评论

暂无评论...
验证码 换一张
取 消