我在过去一天左右一直试图解决这个错误代码,似乎无法找到任何解决方案。我已经回顾了有关此主题的其他帖子,但我仍然输了。如果有人可以看一看,看看为什么我会收到错误,我们将不胜感激:
1364 Field' movie_id'没有默认值,。
谢谢,
大卫
DROP DATABASE movie_tracker;
/*task 1*/
CREATE DATABASE IF NOT EXISTS movie_tracker;
USE movie_tracker;
/*task 2*/
CREATE TABLE movies(
movie_id INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(200)NOT NULL,
release_date DATETIME NOT NULL,
plot_description VARCHAR(4000)NOT NULL
)ENGINE = InnoDB;
CREATE TABLE actors(
actor_id INT (11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR (100) NOT NULL,
last_name VARCHAR (100) NOT NULL,
birth_date DATETIME NOT NULL,
biography VARCHAR (1000) NOT NULL
)ENGINE = InnoDB;
CREATE TABLE locations(
location_id INT (11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
location_name VARCHAR (100) NOT NULL,
street_address VARCHAR (150) NOT NULL,
city VARCHAR(100) NOT NULL,
state CHAR(2) NOT NULL,
zip VARCHAR (5) NOT NUll
)ENGINE = InnoDB;
/*task 3*/
CREATE TABLE movies_actors(
movie_id INT NOT NULL,
actor_id INT NOT NULL
)ENGINE = InnoDB;
CREATE TABLE movies_locations (
movie_id INT (11) NOT NULL,
location_id INT(11) NOT NULL
)ENGINE = InnoDB;
ALTER TABLE movies_actors
ADD COLUMN fk_movie_id INT(11) NOT NULL,
ADD CONSTRAINT fk_movies
FOREIGN KEY (fk_movie_id)
REFERENCES movies (movie_id)
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE movies_actors
ADD COLUMN fk_actor_id INT NOT NULL,
ADD CONSTRAINT fk_actors
FOREIGN KEY(fk_actor_id)
REFERENCES actors (actor_id)
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE movies_locations
ADD COLUMN fk_movie_loc_id INT NOT NULL,
ADD CONSTRAINT fk_movies_loc
FOREIGN KEY (fk_movie_loc_id)
REFERENCES movies(movie_id)
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE movies_locations
ADD COLUMN fk_location_id INT NOT NULL,
ADD CONSTRAINT fk_locations
FOREIGN KEY (fk_location_id)
REFERENCES locations(location_id)
ON UPDATE CASCADE
ON DELETE CASCADE;
/*tast 4*/
INSERT INTO movies(title, release_date, plot_description)
VALUES ('Resident Evil: The Final Chapter','2017-01-27 18:00:00', 'Picking up
immediately after the events in Resident Evil: Retribution, Alice is the only survivor of what was meant to be humanity
s final stand against the undead. Now, she must return to where the nightmare began - The Hive in Raccoon City, where the Umbrella Corporation is gathering its forces for a final strike against
the only remaining survivors of the apocalypse.'),
('Gold','2017-01-22 18:00:00', 'Kenny Wells, a prospector desperate for
a lucky break, teams up with a similarly eager geologist and sets off on an amazing journey to find gold in the uncharted
jungle of Indonesia. Getting the gold was hard but keeping it is even more difficult, sparking an adventure through the most powerful boardrooms of Wall Street'),
('A Dog''s Purpose','2017-02-03 18:00:00', 'A devoted dog (Josh Gad)
discovers the meaning of its own existence through the lives of the humans it teaches to laugh and love. Reincarnated as
multiple canines over the course of five decades, the lovable pooch develops an unbreakable bond with a kindred spirit
named Ethan (Bryce Gheisar). As the boy grows older and comes to a crossroad, the dog once again comes back into his life to remind him of his true self.');
INSERT INTO actors(first_name, last_name, birth_date, biography)
VALUES ('Milla', 'Jovovich', '1975-12-17 01:00:00', 'Milla Jovovich is an Ukrainian-born
actress, supermodel, fashion designer, singer and public figure, who was on the cover
of more than a hundred magazines, and starred in such films as The Fifth Element (1997),
Ultraviolet (2006), and the Resident Evil (2002) franchise. '),
('Matthew', 'McConaughey', '1969-11-04 01:00:00', 'American actor and producer
Matthew David McConaughey was born in Uvalde, Texas. His mother, Mary Kathleen (McCabe), is a substitute school teacher originally
from New Jersey. His father, James Donald McConaughey, was a Mississippi-born gas station owner who ran an oil pipe supply business. '),
('Josh', 'Gad', '1981-02-23 18:00:00', 'Josh Gad was born on February 23, 1981 in
Hollywood, Florida, USA. He is an actor and writer, known for Frozen (2013), Love & Other Drugs (2010) and The
Wedding Ringer (2015). ');
INSERT INTO locations (location_name, street_address, city, state, zip)
VALUES ('AMC Loews Waterfront 22', '300 W Waterfront Dr.', 'West Homestead', 'PA', '15120'),
('Cinemark North Hills and XD', 'McCandless Crossing, 851 Providence Blvd', 'Pittsburgh', 'PA', '15237'),
('Century Square Luxury Cinemas', '2001 Mountain View Dr.', 'West Mifflin', 'PA', '15122');
/*task 5*/
ALTER TABLE movies_locations
ADD COLUMN show_time TIME NOT NULL,
ADD COLUMN view_format VARCHAR (50) NOT NULL;
INSERT INTO movies_locations(show_time, view_format)
VALUES (183000,'Standard'),
(190000,'IMAX'),
(214500,'3D');
ALTER TABLE movies_actors
ADD COLUMN character_name VARCHAR (100) NOT NULL,
ADD COLUMN lead_role VARCHAR (5) NULL,
ADD COLUMN support_role VARCHAR (5) NULL;
INSERT INTO movies_actors(character_name, lead_role, support_role)
VALUES ('Alicia Marcus', 'YES', 'NO'),
('Kenny Wells', 'YES', 'NO'),
('Bailey / Buddy / Tino / Ellie (voice)', 'YES', 'NO');
/*task 6*/
答案 0 :(得分:1)
此行导致错误
INSERT INTO movies_locations(show_time,view_format) 价值观(183000,'标准'), (190000, 'IMAX'), (214500, '3D');
您必须在插入查询中添加movie_id和location_id,因为它们是外键并标记为NOT NULL。
我不知道为什么你增加了两列
ALTER TABLE movies_locations ADD COLUMN fk_movie_loc_id INT NOT NULL,
ALTER TABLE movies_locations ADD COLUMN fk_location_id INT NOT NULL,
我认为你应该删除这两列,如果你更正你的插入查询,就像这个问题可能会解决。
INSERT INTO movies_locations(movie_id,location_id,show_time,view_format) VALUES(movieid,locationid,183000,'标准');