首页 > 解决方案 > 表中不存在 MySQL 键列“product_id”

问题描述

我正在尝试按照这个视频上课,但我遇到了一个错误,但我看不到它在视频中的位置,而且我对使用命令提示符和 MySQL 来查看它太陌生了。

这是错误“第 49 行:表中不存在键列‘product_id’”

这是需要的视频https://www.youtube.com/watch?v=ec--JuXWVu4

这是代码

create database if not exists customers;

use customers;

drop table if exists phonenumbers;
drop table if exists product_orders;
drop table if exists products;
drop table if exists orders;
drop table if exists customers;

CREATE TABLE customers (
    id int(11) NOT NULL auto_increment,
    first_name varchar(20) NOT NULL,
    last_name varchar(20) NOT NULL,
    street varchar(25),
    state char(2) NOT NULL,
    zip char(5),
    city varchar(20),
    PRIMARY KEY(id)
);

CREATE TABLE phonenumbers (
    id int(11) NOT NULL auto_increment,
    customer_id int(11) NOT NULL,
    phone_number varchar(10) NOT NULL,
    PRIMARY KEY(id),
    FOREIGN KEY(customer_id) references customers(id)
);

create table orders (
    id int(11) NOT NULL auto_increment,
    customer_id int(11) NOT NULL,
    date_ordered datetime default current_timestamp,
    date_delivered datetime,
    total decimal(7, 2), 
    PRIMARY KEY(id),
    FOREIGN KEY(customer_id) references customers(id)
);

create table products (
    id int(11) NOT NULL auto_increment,
    name varchar(50) NOT NULL,
    description varchar(255),
    price decimal(5, 2) NOT NULL,
    qty int(10) NOT NULL,
    PRIMARY KEY(id)
);

create table product_orders (
    product_is int(11) NOT NULL,
    order_id int(11) NOT NULL,
    qty int(10) NOT NULL,
    PRIMARY KEY(product_id, order_id),
    FOREIGN KEY(product_id) references products(id),
    FOREIGN KEY(order_id) references orders(id)
);

标签: mysql

解决方案


product_int(11) NOT NULL,正确的是 product_id,对吗?


推荐阅读