Código de error: 1005 no se puede crear la tabla 'custom_db2.durableprofile' (errno: 150)
-
21-12-2019 - |
Pregunta
no se puede crear la base de datos
--------------------------------------------------------
create table DurableArticle(
durable_code varchar(30) not null,
durable_name varchar(100),
durable_number varchar(20),
durable_brandname varchar(125),
durable_modelordetail varchar(125),
durable_price varchar(20),
durable_entrance varchar(20),
constraint durable_PK primary key (durable_code)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
---------------------------------------------
create table DurableProfile(
profile_year integer not null,
profile_status varchar(100),
profile_note varchar(100),
staff_id integer not null,
owner_id integer not null,
room_id integer not null,
durable_code varchar(30) not null,
constraint profile_PK primary key (profile_year,durable_code),
constraint profile_FK1 foreign key (staff_id) references staff(staff_id),
constraint profile_FK2 foreign key (owner_id) references owner(owner_id),
constraint profile_FK3 foreign key (room_id) references room(room_id),
constraint profile_Fk4 foreign key (durable_code) references durablearticle (durable_code)
)ENGINE=InnoDB;
Solución
Usted hace referencia a 3 tablas en la segunda declaración, que obviamente no existe (todavía). Retire las llaves extrañas o cree esas tablas, luego funciona.
create table DurableProfile(
profile_year integer not null,
profile_status varchar(100),
profile_note varchar(100),
staff_id integer not null,
owner_id integer not null,
room_id integer not null,
durable_code varchar(30) not null,
constraint profile_PK primary key (profile_year,durable_code),
constraint profile_Fk4 foreign key (durable_code) references durablearticle (durable_code)
)ENGINE=InnoDB;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow