Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

How to cre and Sqlite3 database and tables

$
0
0

I am trying to create a web app using python and flask.

I got my routing parts done, and now I am trying to set up a Sqlite3 database to store users information.

The following is my code.

from flask import Flask, render_template, redirect, requestimport sqlite3from flask_sqlalchemy import SQLAlchemyfrom flask_login import UserMixinfrom flask_login import LoginManagerlogin_manager = LoginManager()app = Flask(__name__)#To connect the database with the appapp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tekken.db'db = SQLAlchemy(app)class User(db.Model):    id = db.Column(db.Integer, primary_key=True)    username = db.Column(db.String(20), nullable=False)    email = db.Column(db.String(20), nullable=False)    password = db.Column(db.String(80), nullable=False)

I saved the code and opened flask shell in my terminal, and then I ran the following command.

db.create_all()

After running the command, I opened another terminal window and ran the following command.

sqlite 3 tekken.db.tables;

However, it says "Error: in prepare, near "tables": syntax error (1)", and it seems like the users table was never created.

What am I missing in my code?


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>