https://github.com/demoskp/flask-sqlalchemy-tutorial
https://github.com/demoskp/flask-sqlalchemy-tutorial
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/demoskp/flask-sqlalchemy-tutorial
- Owner: demoskp
- Created: 2023-03-14T12:37:14.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-04T08:51:55.000Z (almost 2 years ago)
- Last Synced: 2024-08-13T07:08:28.263Z (8 months ago)
- Language: Python
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - demoskp/flask-sqlalchemy-tutorial - (Python)
README
## Populating the database with users
- First open a Flask shell session by running `flask shell` in your terminal
- Import the `db` object by running `from app import db`
- Import the sql script by running `sql = open("users.sql", "r")`
- Get the sql statement by running `statement = sql.read()`
- Import the `text` function from sqlalchemy by running `from sqlalchemy import text`
- Run the sql statement by running `db.session.execute(text(statement))`
- Finally, commit the transaction by running `db.session.commit()`