create table parts(
cpu char(20) not null,
primary key(cpu)
)engine=innodb;
create table pc(
cpumodel char(20) not null,
index(cpumodel),
foreign key(cpumodel) references parts(cpu)
)engine=innodb; 我用mysql 的工具中 输入上面的的sql中,出现 can't create table 'parts' (errno:150但是如果我一个表一个表(先执行parts的sql,然后再执行pc的sql),又可以正常执行请问是什么问题的
cpu char(20) not null,
primary key(cpu)
)engine=innodb;
create table pc(
cpumodel char(20) not null,
index(cpumodel),
foreign key(cpumodel) references parts(cpu)
)engine=innodb; 我用mysql 的工具中 输入上面的的sql中,出现 can't create table 'parts' (errno:150但是如果我一个表一个表(先执行parts的sql,然后再执行pc的sql),又可以正常执行请问是什么问题的
你是在什么中执行的?在MYSQL命令工具中试一下,然后贴出你的结果如下。 应该是你的工具的问题。
mysql> create table parts(
-> cpu char(20) not null,
-> primary key(cpu)
-> )engine=innodb;
Query OK, 0 rows affected (0.34 sec)mysql> create table pc(
-> cpumodel char(20) not null,
-> index(cpumodel),
-> foreign key(cpumodel) references parts(cpu)
-> )engine=innodb;
Query OK, 0 rows affected (0.16 sec)mysql>
感觉有时候有个空格也会出现错误,好晕