python
Basic types and relationship in SQLAlchemy
from database import db, Base
from marshmallow import Schema, fields
from datetime import datetime as date
class Employee(db.Model):
__tablename__ = "employee"
id = db.Column(db.Integer, primary_key=True, autoincrement=True, mssql_identity_start=100000)
employee_uid = db.Column(db.Integer, unique=True)
employee_email = db.Column(db.String, nullable=False)
employee_name = db.Column(db.String(200), nullable=True)
created_on = db.Column(db.DateTime, default=date.now())
class EmployeeAddress(db.Model):
__tablename__ = "employee_address"
id = db.Column(db.Integer, primary_key=True, autoincrement=True, mssql_identity_start=100000)
employee_id = db.Column(db.Integer, db.ForeignKey('employee.id'), nullable=False)
employee = db.relationship('Employee')
employee_address = db.Column(db.Text, nullable=False)
Output
Create integer, string type column, and relationship in SQLAlchemy
Was this helpful?
Similar Posts