Scripts & Migrate
Install Scripts
pip install flask-script
New file to create and delete DB
in root level create manaage.py
from ict import app, db
from flask_script import Manager, prompt_bool
from ict import db
from model import Engineer
manager = Manager(app)
@manager.command
def initdb():
db.create_all()
db.session.add(Engineer(signum="erodvel", name="Rod"))
db.session.commit()
print ('Iniatialized DB')
@manager.command
def dropdb():
if prompt_bool("Are you want to clear DB"):
db.drop_all()
print ('Dropped the DB')
if __name__ == '__main__':
manager.run()
In the console
Add register.
python
from ict import db
from model import Engineer
db.session.add(Engineer(signum="erodvel", name="Rod"))
db.session.commit()
Install Scripts
pip install flask-script
New file to create and delete DB
in root level create manaage.py
- @manager.command enable the method from the console
from ict import app, db
from flask_script import Manager, prompt_bool
from ict import db
from model import Engineer
manager = Manager(app)
@manager.command
def initdb():
db.create_all()
db.session.add(Engineer(signum="erodvel", name="Rod"))
db.session.commit()
print ('Iniatialized DB')
@manager.command
def dropdb():
if prompt_bool("Are you want to clear DB"):
db.drop_all()
print ('Dropped the DB')
if __name__ == '__main__':
manager.run()
In the console
- Type python manager.py to show all the commands
- dropdb
- initdb
- python manager.py dropdb
- python manager.py runserver - starts the server
Add register.
python
from ict import db
from model import Engineer
db.session.add(Engineer(signum="erodvel", name="Rod"))
db.session.commit()
Comentarios
Publicar un comentario