There is no data in the database created by flask_sqlalchemy?

I encountered a problem when I used flask_sqlalchemy for the first time, as follows

uses python version 3.6 , uses conda as the package manager, and has successfully installed flask_sqlalchemy and other related dependent packages.

the simple directory of the project is as follows:

app.py
db/
models/
    __init__.py
    todo.py
routes/
    __init__.py
    todo.py
static/
templates/

app.py the contents of the file are as follows:

>>> from app import db
>>> db.create_all()

problems are as follows:
check the file directory at this time and find that there is a data.sqlite file under models/ , but there is no content in the file, the display size is 0 byte , and I use database management software to check and find that there is no data in any table. At the same time, if I continue to execute db.drop_all , I cannot delete the database file.

I would like to ask how to solve this situation. I Googled it and couldn"t find the answer. I hope I can get some advice from my predecessors. I would appreciate it.


you have to declare the model structure before calling db.create_all () .

like this

from app import db
from models import todo
db.create_all()

One of the seniors at the bottom of

has answered quite well, and I have also found some related articles in stackoverflow . At the same time, there is another mistake in my own code. Let me sum it up:

if I quote db in app.py in models/todo.py and the module in models in app.py , resulting in circular references reporting errors, I think it's better to do this:

.
  • initialize db in models , where db can be initialized without app , as follows
   create_all ()  Import the data file before  

					
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be8142-318ec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be8142-318ec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?