1
您好我想在Postgres中使用SQLAlchemy創建一個表,它處理的都很好,但是表並沒有在我的Postgres服務器中創建。如何使用Postgres在SQLAlchemy中創建表?
我的models.py文件:
import sqlalchemy
from sqlalchemy import Column, Integer, String
from sqlalchemy import Table
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class MyTable(Base):
__tablename__ = 'myTable'
time_id = Column(String(), primary_key=True)
customer_id = Column(String())
inventory_id = Column(String())
def toJSON(self):
json = {
"time_id":self.alert_id,
"customer_id":self.customer_id,
"inventory_id":self.inventory_id,
}
return json
我的創造者文件:
from sqlalchemy.ext.declarative import declarative_base
from models import MyTable
from sqlalchemy import create_engine
path="postgresql://postgres:[email protected]/test"
engine = create_engine(path, echo=True)
Base = declarative_base()
Base.metadata.create_all(engine)
我做錯了嗎?