mysql-error-1005

MySQL. Can't create table errno 150

半城伤御伤魂 提交于 2019-11-26 13:50:09
问题 I have to create a database with two tables in MySQL, but the script fails with errno 150 (foreign key problem). I double-checked the foreign key fields to be the same on both tables, and I can't find any error. Here is the script: SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; DROP SCHEMA IF EXISTS `testdb`; CREATE SCHEMA IF NOT EXISTS `testdb` DEFAULT

Error Code: 1005. Can't create table '…' (errno: 150)

坚强是说给别人听的谎言 提交于 2019-11-26 10:17:56
I searched for a solution to this problem on the Internet and checked the Stack Overflow questions, but none of the solutions worked for my case. I want to create a foreign key from table sira_no to metal_kod. ALTER TABLE sira_no ADD CONSTRAINT METAL_KODU FOREIGN KEY(METAL_KODU) REFERENCES metal_kod(METAL_KODU) ON DELETE SET NULL ON UPDATE SET NULL ; This script returns: Error Code: 1005. Can't create table 'ebs.#sql-f48_1a3' (errno: 150) I tried adding an index to the referenced table: CREATE INDEX METAL_KODU_INDEX ON metal_kod (METAL_KODU); I checked METAL_KODU on both tables (charset and

MySQL Foreign Key Error 1005 errno 150

霸气de小男生 提交于 2019-11-26 03:24:18
问题 I\'m doing a small DataBase with MySQL Workbench. I have a main table, called \"Immobili\", which has a Primary Key composed by four columns: (Comune, Via, Civico, Immobile). Now, I also have three other tables, wich have the same primary key (Comune, Via, Civico, Immobile), but these fields are also referenced to the table Immobili. First question: Can I make a Primary Key that is also a Foreign Key? Second Question: When I try to export the changes it says: Executing SQL script in server #

MySQL Foreign Key Error 1005 errno 150

北城余情 提交于 2019-11-25 22:24:27
I'm doing a small DataBase with MySQL Workbench. I have a main table, called "Immobili", which has a Primary Key composed by four columns: (Comune, Via, Civico, Immobile). Now, I also have three other tables, wich have the same primary key (Comune, Via, Civico, Immobile), but these fields are also referenced to the table Immobili. First question: Can I make a Primary Key that is also a Foreign Key? Second Question: When I try to export the changes it says: Executing SQL script in server # ERROR: Error 1005: Can't create table 'dbimmobili.condoni' (errno: 150) CREATE TABLE IF NOT EXISTS