I'd read the docs but overlooked where it says " two primary arguments are the table name, then the MetaData object which it will be associated with". I changed my Flask models to SQLAlchemy's Table() rather than classes, then rather than importing the tables into my other file, I imported Metadata() from Flask's models.py. I hope this makes some sense and thanks for getting this far!Įdit: As with most problems like this the solution is pretty straightforward and obvious. Just to be clear, I'm using Flask-SQLAlchemy in my Flask project, and standard SQLAlchemy in my create/insert/update ones and I'd hoped that they would play nicely together. It had complained about not being able to create certain relationships because tables didn't exist yet, but at least it was reading the models correctly, and temporarily commenting those lines out got rid of that, but still not tables in the SQLite file.ĭoes anyone have any tips on how to use the Flask-SQLAlchemy models to create a SQLite DB file, outside of Flask, or am I heading down an impossible route and will just have to have them hardcoded coded separately? Though when I've tried importing the Flask models into my create script, and calling create_all() but this just creates an empty SQLite file. When I run the create script with the each table written out explicitly, everything turns out perfectly. To create my blank DB I have a script, which had originally just used SQL commands rather than SQLAlchemy ones, to create the tables, and to insert/update the data, etc. The DB is pre-populated with data, and not user filled, so I create the DB beforehand, and update it as required myself. I followed the Mega-Tutorial for the basis of some things, so have my DB models as classes with some relationships etc. Its not a completely different project, more the backend for Flask's front.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |