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

你说的曾经没有我的故事 提交于 2019-12-08 01:32:13

问题


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)
);

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)

回答1:


MySQL Creating tables with Foreign Keys giving errno: 150




回答2:


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;


来源:https://stackoverflow.com/questions/3128115/mysql-error-1005-hy000-cant-create-table-receitascakephp-recipes-errno

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!