from flask_sqlalchemy import Model
from sqlalchemy import Column, Integer, Unicode, UnicodeText, ForeignKey
from sqlalchemy.orm import relationship


class User(Model):
    __tablename__ = "user"
    ROLE_ADMIN = 0
    ROLE_USER = 1
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(64), index=True)
    username = Column(Unicode(20), index=True)
    password_hash = Column(Unicode(120))
    role = Column(Integer, default=ROLE_USER)
    postings = relationship("Posting", backref="user")


class Posting(Model):
    __tablename__ = "posting"
    id = Column(Integer, primary_key=True)
    title = Column(Unicode(64), index=True)
    description = Column(1200)
    price = Column(Integer, default=100)
    user_id = ForeignKey("user.id", index=True)



from flask_sqlalchemy import Model
from __init__ import db


class User(Model):
    __tablename__ = "user"
    ROLE_ADMIN = 0
    ROLE_USER = 1
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode(64), index=True)
    username = db.Column(db.Unicode(20), index=True)
    password_hash = db.Column(db.Unicode(120))
    role = db.Column(db.Integer, default=ROLE_USER)
    postings = db.relationship("Posting", backref="user")


class Posting(Model):
    __tablename__ = "posting"
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Unicode(64), index=True)
    description = db.Column(1200)
    price = db.Column(db.Integer, default=100)
    user_id = db.ForeignKey("user.id", index=True)



Use local database namespace instead of package.
Use local database namespace instead of package.

  from flask_sqlalchemy import Model
+ from __init__ import db
- from sqlalchemy import Column, Integer, Unicode, UnicodeText, ForeignKey
- from sqlalchemy.orm import relationship
  
  
  class User(Model):
      __tablename__ = "user"
      ROLE_ADMIN = 0
      ROLE_USER = 1
-     id = Column(Integer, primary_key=True)
+     id = db.Column(db.Integer, primary_key=True)
-     name = Column(Unicode(64), index=True)
+     name = db.Column(db.Unicode(64), index=True)
-     username = Column(Unicode(20), index=True)
+     username = db.Column(db.Unicode(20), index=True)
-     password_hash = Column(Unicode(120))
+     password_hash = db.Column(db.Unicode(120))
-     role = Column(Integer, default=ROLE_USER)
+     role = db.Column(db.Integer, default=ROLE_USER)
-     postings = relationship("Posting", backref="user")
+     postings = db.relationship("Posting", backref="user")
  
  
  class Posting(Model):
      __tablename__ = "posting"
-     id = Column(Integer, primary_key=True)
+     id = db.Column(db.Integer, primary_key=True)
-     title = Column(Unicode(64), index=True)
+     title = db.Column(db.Unicode(64), index=True)
-     description = Column(1200)
+     description = db.Column(1200)
-     price = Column(Integer, default=100)
+     price = db.Column(db.Integer, default=100)
-     user_id = ForeignKey("user.id", index=True)
+     user_id = db.ForeignKey("user.id", index=True)
  
  
  
Use local database namespace instead of package.
## Code Before:
from flask_sqlalchemy import Model
from sqlalchemy import Column, Integer, Unicode, UnicodeText, ForeignKey
from sqlalchemy.orm import relationship


class User(Model):
    __tablename__ = "user"
    ROLE_ADMIN = 0
    ROLE_USER = 1
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(64), index=True)
    username = Column(Unicode(20), index=True)
    password_hash = Column(Unicode(120))
    role = Column(Integer, default=ROLE_USER)
    postings = relationship("Posting", backref="user")


class Posting(Model):
    __tablename__ = "posting"
    id = Column(Integer, primary_key=True)
    title = Column(Unicode(64), index=True)
    description = Column(1200)
    price = Column(Integer, default=100)
    user_id = ForeignKey("user.id", index=True)



## Instruction:
Use local database namespace instead of package.
## Code After:
from flask_sqlalchemy import Model
from __init__ import db


class User(Model):
    __tablename__ = "user"
    ROLE_ADMIN = 0
    ROLE_USER = 1
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode(64), index=True)
    username = db.Column(db.Unicode(20), index=True)
    password_hash = db.Column(db.Unicode(120))
    role = db.Column(db.Integer, default=ROLE_USER)
    postings = db.relationship("Posting", backref="user")


class Posting(Model):
    __tablename__ = "posting"
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Unicode(64), index=True)
    description = db.Column(1200)
    price = db.Column(db.Integer, default=100)
    user_id = db.ForeignKey("user.id", index=True)


