Fix error in model.
The two channel ids need to be NULL by default, don't know them on object creation.
This commit is contained in:
+12
-12
@@ -1,9 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from sqlmodel import Session, create_engine, select
|
from sqlmodel import Session, SQLModel, create_engine, select
|
||||||
|
|
||||||
from models import Guild
|
from models import CategoryGroup, Guild
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
@@ -12,19 +12,19 @@ SQL_HOST = os.getenv("SQL_HOST", "")
|
|||||||
SQL_PASS = os.getenv("SQL_PASS", "")
|
SQL_PASS = os.getenv("SQL_PASS", "")
|
||||||
SQL_USER = os.getenv("SQL_USER", "")
|
SQL_USER = os.getenv("SQL_USER", "")
|
||||||
|
|
||||||
# url = "sqlite:///database.db"
|
url = "sqlite:///database.db"
|
||||||
url = f"mysql+pymysql://{SQL_USER}:{SQL_PASS}@{SQL_HOST}/{SQL_DB}"
|
# url = f"mysql+pymysql://{SQL_USER}:{SQL_PASS}@{SQL_HOST}/{SQL_DB}"
|
||||||
engine = create_engine(url)
|
engine = create_engine(url)
|
||||||
# SQLModel.metadata.create_all(engine)
|
SQLModel.metadata.create_all(engine)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# guild = Guild(id=1, name="test guild", submission_channel=1, verification_channel=2)
|
guild = Guild(id=1, name="test guild")
|
||||||
# session.add(guild)
|
session.add(guild)
|
||||||
# group1 = CategoryGroup(name="group1", channel_id=1, guild_id=1, message_id=1)
|
group1 = CategoryGroup(name="group1", channel_id=1, guild_id=1, message_id=1)
|
||||||
# group2 = CategoryGroup(name="group2", channel_id=2, guild_id=1, message_id=2)
|
group2 = CategoryGroup(name="group2", channel_id=2, guild_id=1, message_id=2)
|
||||||
# session.add(group1)
|
session.add(group1)
|
||||||
# session.add(group2)
|
session.add(group2)
|
||||||
# session.commit()
|
session.commit()
|
||||||
|
|
||||||
# anotherone = Guild(id=2, name="test guild 2", submission_channel=1, verification_channel=2)
|
# anotherone = Guild(id=2, name="test guild 2", submission_channel=1, verification_channel=2)
|
||||||
# session.add(anotherone)
|
# session.add(anotherone)
|
||||||
|
|||||||
+6
-2
@@ -22,8 +22,12 @@ class Guild(SQLModel, table=True):
|
|||||||
id: int = Field(sa_column=Column("GuildId", BIGINT(unsigned=True), primary_key=True, nullable=False))
|
id: int = Field(sa_column=Column("GuildId", BIGINT(unsigned=True), primary_key=True, nullable=False))
|
||||||
name: str = Field(sa_column=Column("GuildName", VARCHAR), max_length=95)
|
name: str = Field(sa_column=Column("GuildName", VARCHAR), max_length=95)
|
||||||
# deprecated, not currently used.
|
# deprecated, not currently used.
|
||||||
submission_channel: int = Field(sa_column=Column("SubmissionChannel", BIGINT(unsigned=True)))
|
submission_channel: int | None = Field(
|
||||||
verification_channel: int = Field(sa_column=Column("VerificationChannel", BIGINT(unsigned=True)))
|
sa_column=Column("SubmissionChannel", BIGINT(unsigned=True), nullable=True), default=None
|
||||||
|
)
|
||||||
|
verification_channel: int | None = Field(
|
||||||
|
sa_column=Column("VerificationChannel", BIGINT(unsigned=True), nullable=True), default=None
|
||||||
|
)
|
||||||
active: bool = Field(sa_column=Column("Active", BOOLEAN), default=True)
|
active: bool = Field(sa_column=Column("Active", BOOLEAN), default=True)
|
||||||
|
|
||||||
category_groups: list["CategoryGroup"] = Relationship(back_populates="guild", cascade_delete=True)
|
category_groups: list["CategoryGroup"] = Relationship(back_populates="guild", cascade_delete=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user