use this er diagram generator code:
Modify this code to update the DB schema diagram.
To reset the sample schema, replace everything with
two dots ('..' - without quotes).
Customer
CustomerID PK int
Name string INDEX
Address1 string
Address2 NULL string
Address3 NULL string
Order
OrderID PK int
CustomerID int FK >- Customer.CustomerID
TotalAmount money
OrderStatusID int FK >- os.OrderStatusID
OrderLine as ol
OrderLineID PK int
OrderID int FK >- Order.OrderID
ProductID int FK >- p.ProductID
Quantity int
Table documentation comment 1 (try the PDF/RTF export)
Product as p # Table documentation comment 2
ProductID PK int
Field documentation comment 1
Field documentation comment 2
Name varchar(200) UNIQUE # Field documentation comment 3
Price money
OrderStatus as os
OrderStatusID PK int
Name UNIQUE string
as an example, and give me the code to generate an er diagram for this database which is in sqlite3:
Create CITY table
cursor.execute('''
CREATE TABLE IF NOT EXISTS CITY (
id INTEGER PRIMARY KEY,
name TEXT,
description TEXT
)
''')
Create DISTRICT table
cursor.execute('''
CREATE TABLE IF NOT EXISTS DISTRICT (
id INTEGER PRIMARY KEY,
name TEXT,
population INTEGER,
city_id INTEGER,
FOREIGN KEY(city_id) REFERENCES CITY(id)
)
''')
Create LANDMARK table
cursor.execute('''
CREATE TABLE IF NOT EXISTS LANDMARK (
id INTEGER PRIMARY KEY,
name TEXT,
type TEXT,
description TEXT,
city_id INTEGER,
FOREIGN KEY(city_id) REFERENCES CITY(id)
)
''')
Create STREET table
cursor.execute('''
CREATE TABLE IF NOT EXISTS STREET (
id INTEGER PRIMARY KEY,
name TEXT,
description TEXT,
district_id INTEGER,
FOREIGN KEY(district_id) REFERENCES DISTRICT(id)
)
''')
Create TOURIST table
cursor.execute('''
CREATE TABLE IF NOT EXISTS TOURIST (
id INTEGER PRIMARY KEY,
name TEXT,
nationality TEXT,
landmark_id INTEGER,
FOREIGN KEY(landmark_id) REFERENCES LANDMARK(id)
)
''')
Create VENDOR table
cursor.execute('''
CREATE TABLE IF NOT EXISTS VENDOR (
id INTEGER PRIMARY KEY,
name TEXT,
goodsSold TEXT,
street_id INTEGER,
FOREIGN KEY(street_id) REFERENCES STREET(id)
)
''')
Create RIVER table
cursor.execute('''
CREATE TABLE IF NOT EXISTS RIVER (
id INTEGER PRIMARY KEY,
name TEXT,
length FLOAT
)
''')
Create BRIDGE table
cursor.execute('''
CREATE TABLE IF NOT EXISTS BRIDGE (
id INTEGER PRIMARY KEY,
name TEXT,
yearBuilt INTEGER,
river_id INTEGER,
FOREIGN KEY(river_id) REFERENCES RIVER(id)
)
''')