-
In the example code, all the How to delay the setting of this field until I actually have created a Setting it to
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Answering own question It seems model classes can be defined without issue containing a |
Beta Was this translation helpful? Give feedback.
-
I have the same question but I don't know the database URL string in advance. Is there a clean way to create an uninitialized database and setting the URL connection string later? What I do now is quiet a nasty workaround, something akin to async def main():
config = load_config_from_disk()
# Need to set DATABASE_URL so it can be read in db.py to pass to the database object.
os.environ["DATABASE_URL"] = config.database_url
# Now import the database module.
from . import db
# ... And in class BaseMeta(ormar.ModelMeta):
database_url = os.environ["DATABASE_URL"]
database = databases.Database(database_url)
metadata = sqlalchemy.MetaData() |
Beta Was this translation helpful? Give feedback.
Answering own question
It seems model classes can be defined without issue containing a
database
object in the meta class that hasn't been connected to yet. So we can connect later. This thread can be closed.