使用 sqlalchemy 创建表时我在这里遗漏了什么吗?
from sqlalchemy import create_engine
from sqlalchemy import MetaData, Column, Table, ForeignKey
from sqlalchemy import Integer, String, DateTime
engine = create_engine('postgresql+psycopg2://postgres:password#@localhost:5432/LabData',echo=True)
metadata=MetaData(bind=engine)
main_table=('sample',metadata,
Column('LIN',String(10),primary_key=True),
Column('material_type',String(20),nullable=False),
Column('source',String(20),nullable=False),
Column('material_description',String(100)),
Column('quantity',Integer),
Column('location',String(2)),
Column('received_by',String(20)),
Column('received_date',DateTime,nullable=False),
)
metadata.create_all()
python控制台上的输出是:
2012-04-25 13:13:42,734 INFO sqlalchemy.engine.base.Engine select version()
2012-04-25 13:13:42,796 INFO sqlalchemy.engine.base.Engine {}
2012-04-25 13:13:42,796 INFO sqlalchemy.engine.base.Engine select current_schema()
2012-04-25 13:13:42,796 INFO sqlalchemy.engine.base.Engine {}
当我尝试将数据添加到表中时,它显示 nosuchtableerror。