2017-01-27 18 views
0

このエラーコードを過去1日間に整理しようとしていて、解決策が見つからないようです。私はこのトピックに関する他の投稿を見直しましたが、私はまだ失われています。誰もが見て、私はエラーを取得しています理由を知ることができれば、それは非常に高く評価されるだろう:SQLエラー:1364 'movie_id'フィールドにデフォルト値がありません

1364 Field 'movie_id' doesn't have a default value, .

、ありがとう

デビッド

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

SQLの味は? – STLDeveloper

答えて

1

この行はエラー

の原因になっています

INSERT INTO movies_locations(show_time、view_format) VALUES(183000、 '標準')、 (190000、 'IMAX')、 (214500、 '3D');

外部キーでNOT NULLとマークされているため、挿入クエリにmovie_idとlocation_idを追加する必要があります。

uが2列

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と、

Iを余分に追加した理由を、私はなっておりませんこれらの2つの列を削除する必要があると思うし、この問題のような挿入クエリを修正すると解決できるかもしれません。

INSERT INTO movies_locations(movie_id、location_id、show_time、view_format) VALUES(movieid、locationid、183000、 'Standard');

関連する問題