Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Sqlite3-如何实现一对多关系的存储_Python_Database_Sqlite_One To Many - Fatal编程技术网

Python Sqlite3-如何实现一对多关系的存储

Python Sqlite3-如何实现一对多关系的存储,python,database,sqlite,one-to-many,Python,Database,Sqlite,One To Many,我目前正在开发一个应用程序,将网站信息及其URL存储在SQLite3数据库中 我有两个类,Website和Url,它们都存储我的应用程序所需的数据 网站类初始化如下: class Website: """ Class that represents a project's website. """ def __init__( self, domain, l

我目前正在开发一个应用程序,将网站信息及其URL存储在SQLite3数据库中

我有两个类,
Website
Url
,它们都存储我的应用程序所需的数据

网站
类初始化如下:

class Website:
    """
    Class that represents a project's website.
    """

    def __init__(
        self,
        domain,
        language,
        urls,
    ):
        self.domain = domain
        self.language = language
        self.urls = []
Url
类是这样的:

class Url:
"""
Class that represents an URL associated to a Website instance
"""

def __init__(
    self,
    url,
    title,
    
):
    self.url = url
    self.title = title
我用于创建表的查询如下所示:

CREATE TABLE IF NOT EXISTS websites (
name text NOT NULL UNIQUE,
domain text NOT NULL,
language text NOT NULL);
  

如果
url
参数是第二个表中应该列出的url,那么如何存储
w=Website(“test.com”,“en”,url)
并在数据库中保留关系

我是否应该保存不带URL的
网站
实例,并使用另一个命令单独保存它们?我真的不知道该怎么做。谢谢

CREATE TABLE IF NOT EXISTS urls (
website text NOT NULL,
url text NOT NULL UNIQUE,
title text NOT NULL,
FOREIGN KEY (website) REFERENCES websites(name));