gpt4 book ai didi

MySQL 错误 'Key Column doesnt exist in table'

转载 作者:行者123 更新时间:2023-11-29 04:48:03 25 4
gpt4 key购买 nike

这是我在命令行中的输入,您可以看到我尝试以不同的方式添加外键并不断收到相同的错误我做错了什么?

mysql> create table membership(

-> m_no char(3) primary key,
-> m_fname varchar(15) not null,
-> m_lname varchar(15) not null,
-> m_street varchar(30) not null,
-> m_city varchar(20) not null,
-> m_st char(2) not null,
-> m_balance varchar(3));

查询正常,0 行受影响(1.06 秒)

mysql> create table rental(

-> r_no char(4) primary key,
-> r_date date not null,
-> foreign key (m_no) references membership(m_no));
ERROR 1072 (42000): Key column 'm_no' doesn't exist in table

mysql> create table rental(
-> r_no char(4) primary key,
-> r_date date not null,
-> foreign key (m_no) references membership);
ERROR 1072 (42000): Key column 'm_no' doesn't exist in table

mysql> create table rental(
-> r_no char(4) primary key,
-> r_date date not null,
-> foreign key (m_no) references membership)
-> engine=innodb;
ERROR 1072 (42000): Key column 'm_no' doesn't exist in table


mysql> create table rental(

-> r_no char(4) primary key,
-> r_date date not null,
-> foreign key (m_no) references membership(m_no))
-> engine=innodb;
ERROR 1072 (42000): Key column 'm_no' doesn't exist in table

mysql> create table rental(

-> r_no char(4) primary key,
-> r_date date not null);

查询正常,0 行受影响(0.22 秒)

mysql> alter table rental add foreign key (m_no) references membership(m_no);

ERROR 1072 (42000): Key column 'm_no' doesn't exist in table

数据库>

最佳答案

错误说明很清楚。您的租金表中没有名为“m_no”的列。

这是你想要的吗:

Create table rental
(
r_no char(4) primary key,
r_date date not null,
foreign key (r_no) references membership(m_no)
);

关于MySQL 错误 'Key Column doesnt exist in table',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15841663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com