我使用schema.sql文件成功创建了一个数据库:
CREATE DATABASE movie_db;
\c movie_db
DROP TABLE movies;
CREATE TABLE movies (
id BIGSERIAL PRIMARY KEY,
title VARCHAR(255),
year integer,
description VARCHAR(255),
posterUrl VARCHAR(255),
screenshotUrl VARCHAR(255)
);
但是当我尝试连接seed.sql文件时,它告诉我ERROR: column "After the death of his father, T'Challa returns home to..." does not exist
:
\c movie_db
INSERT INTO movies (title, year, description, posterUrl, screenshotUrl)
VALUES ('Black Panther', 2018, "After the death of his father, T'Challa returns home to...", 'https://ia.media-imdb.com/images/M/MV5BMTg1MTY2MjYzNV5BMl5BanBnXkFtZTgwMTc4NTMwNDI@._V1_UX182_CR0,0,182,268_AL_.jpg', 'http://cdn.wegotthiscovered.com/wp-content/uploads/2017/10/black-panther-movie-image-9.jpg');
我还能够成功插入另一部电影,这部电影在结构上与Black Panther信息相同。
起初我觉得'在T'Challa有一个问题,但当我删除它时,我仍然无法连接。这可能是非常明显的事情,但它一直在困扰我,所以我想我会问听众。
答案 0 :(得分:1)
尝试用单引号括起来:
INSERT INTO movies (title, year, description, posterUrl, screenshotUrl)
VALUES ('Black Panther', 2018, 'After the death of his father, T''Challa returns home to...', 'https://ia.media-imdb.com/images/M/MV5BMTg1MTY2MjYzNV5BMl5BanBnXkFtZTgwMTc4NTMwNDI@._V1_UX182_CR0,0,182,268_AL_.jpg', 'http://cdn.wegotthiscovered.com/wp-content/uploads/2017/10/black-panther-movie-image-9.jpg');
要在SQL中转义单引号,请在一行中使用两个单引号。