-
Notifications
You must be signed in to change notification settings - Fork 1
User Registration
Manish Sah edited this page Sep 18, 2020
·
10 revisions
Create a class Registration which inherits from Sqlalchemy's Model. We will define all the models(Tables) needed for our project in models.py file in blog package
from blog import db
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
password = db.Column(db.String(60), nullable=False)
inheriting Model allows sqlalchemy to interact with a table against the class User.
Now, we need to create a table in the database that resembles our class User
open python console by entering python in the terminal and enter the following commands:
- from blog import db
- from blog.models import User
- db.create_all()
db.create_all() will create a table named "user(the name will be in lowercase)" in our database.