Python 数据库ER关系图未显示关系,即使已指定
我已经创建了一个sqlite数据库。尽管我已经包括了主键和外键之间的关系,但当我生成ER图时,我无法看到它们之间的连接。我正在使用datagrip创建图表。我在datagrip和dbvisualizer中测试了其他数据库,我对它们没有任何问题,只是在这方面 ER图- 这是我用来在数据库中创建两个表的脚本-Python 数据库ER关系图未显示关系,即使已指定,python,sql,sqlite,Python,Sql,Sqlite,我已经创建了一个sqlite数据库。尽管我已经包括了主键和外键之间的关系,但当我生成ER图时,我无法看到它们之间的连接。我正在使用datagrip创建图表。我在datagrip和dbvisualizer中测试了其他数据库,我对它们没有任何问题,只是在这方面 ER图- 这是我用来在数据库中创建两个表的脚本- def create_titles_table(): # connect to the database conn = sqlite3.connect("imdb.
def create_titles_table():
# connect to the database
conn = sqlite3.connect("imdb.db")
# create a cursor
c = conn.cursor()
print()
print("Creating titles table...")
c.execute(
"""CREATE TABLE IF NOT EXISTS titles
(titleId TEXT NOT NULL, titleType TEXT,
primaryTitle TEXT, originalTitle TEXT,
isAdult INTEGER, startYear REAL,
endYear REAL, runtimeMinutes REAL,
PRIMARY KEY (titleId)
)
"""
)
# commit changes
conn.commit()
# read the title data
df = load_data("title.basics.tsv")
# replace \N with nan
df.replace("\\N", np.nan, inplace=True)
# rename columns
df.rename(columns={"tconst": "titleId"}, inplace=True)
# drop the genres column
title_df = df.drop("genres", axis=1)
# convert the data types from str to numeric
title_df["startYear"] = pd.to_numeric(title_df["startYear"], errors="coerce")
title_df["endYear"] = pd.to_numeric(title_df["endYear"], errors="coerce")
title_df["runtimeMinutes"] = pd.to_numeric(
title_df["runtimeMinutes"], errors="coerce"
)
# insert the data into titles table
title_df.to_sql("titles", conn, if_exists="replace", index=False)
# commit changes
conn.commit()
# close the connection
conn.close()
print("Completed!")
print()
def create_ratings_table():
# connect to the database
conn = sqlite3.connect("imdb.db")
# create a cursor
c = conn.cursor()
print()
print("Creating ratings table...")
c.execute(
"""CREATE TABLE IF NOT EXISTS ratings
(titleId TEXT NOT NULL, averageRating REAL, numVotes INTEGER,
FOREIGN KEY (titleId) REFERENCES titles(titleId)
)
"""
)
# commit changes
conn.commit()
# read the data
df = load_data("title.ratings.tsv")
df.rename(columns={"tconst": "titleId"}, inplace=True)
# insert the data into the ratings table
df.to_sql("ratings", conn, if_exists="replace", index=False)
# commit changes
conn.commit()
# close the connection
conn.close()
print("Completed!")
print()
有人能告诉我哪里出错了吗?你是如何创建图表的?@mkrieger1我右键单击datagrip中的数据库,然后选择“图表>显示可视化”并从中保存它。