Today, we will be diving into Flask concepts and best practices.
- First we must import SQLAlchemy.
from flask_sqlalchemy import SQLAlchemy
class Employee(db.Model):
tablename = ‘soccer_positions’
id = db.Column(db.Integer, primary_key=True)
position1 = db.Column(db.String)
position2 = db.Column(db.String)
position3 = db.Column(db.String)
When we are creating a table. We always start with an id to keep track of our table columns.As listed above, we use the id.Integer to show that our id can only be a number/integer and not a text. The next line, we give the variable a name and use db.Column. Could you guess what does the db.Column is for. If you guessed that we use this to create another column in the soccer_positions table, you are correct. Just like db.Integer, we use db.String to make sure that our column can only be a string. Take some time and get some practice with the basics. Next we will talk about relationships between tables.