为什么在SQLAlchemy的Python控制台中的base.metadata.create_all(engine)中不显示表?

错误编码:

我正在尝试创建数据库并在其中插入值。我正在使用postgres数据库。我跟随时没有看到任何错误

>>> from sqlalchemy import create_engine
>>> engine = create_engine('postgresql://postgres:password@localhost:5432/mydatabase')
>>> from sqlalchemy.ext.declarative import declarative_base
>>> Base = declarative_base()
>>> from sqlalchemy import Column, Integer, String
>>> class User(Base):
...     __tablename__ = 'users'
...     id = Column(Integer, primary_key=True)
...     fullname = Column(String)
...     password = Column(String)
...     
...     def __repr__(self):
...             return "<User(name='%s', fullname='%s', password='%s')>" % (self.name, self.fullname, self.password)


>>> User.__table__

给我

Table('users', MetaData(bind=None), Column('id', Integer(), table=<users>, primary_key=True, nullable=False), Column('fullname', String(), table=<users>), Column('password', String(), table=<users>), schema=None)

但是当我跑步时

>>> Base.metadata.create_all(engine)

什么都没有显示,在文档中给出了表及其属性,但是运行Base.metadata.create_all(engine)后什么也看不到

有人可以提出解决办法吗?

大卫主义:

如果要查看SQLAlchemy发送的命令,请echo在引擎中打开

engine = create_engine('postgresql://...', echo=True)

当然,您以后总是可以使用psql或其他工具查看数据库

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么DataFrame表spyder和python控制台中的日期时间格式不同

SQLAlchemy create_all()不创建表

为什么我的Safari应用程序扩展NSLog消息未在Xcode的控制台中显示?

为什么以CLI开头的Amazon EMR集群未显示在Web控制台中?

为什么是Eclipse-Tomcat 7在控制台中将所有文本显示为红色

为什么可以重用SQLalchemy create_all()?

为什么我在JavaScript中的控制台中未定义

为什么我的print()命令在控制台中显示双打?

为什么“失败重试”在Google Cloud Functions控制台中显示为灰色?

从Python中的SQLAlchemy了解MetaData()

为什么不同的ConsoleColor值在控制台中以相同的渲染颜色显示?

为什么char数组在控制台中显示内容,而string和int数组在c#中却不显示?

Base.metadata如何在Sqlalchemy中工作?

为什么在Postgresql控制台中查询正常时查询不会保存在csv文件中

C ++控制台中的星号列出了文件夹中的所有文件,为什么?

为什么我的脚本可以运行,但是在控制台中显示语法错误?

为什么我的__proto__参考在控制台中显示错误的名称?

为什么在控制台中而不是在Eclipse / PyDev中运行Python脚本时引发UnicodeDecodeError?

当您在Rails控制台中调用.all时,为什么表中除第一行以外的所有行都显示为“#”?

为什么ActivityViewController在控制台中显示自动约束错误?

为什么字符串中的反斜杠(\)在控制台中给出错误

为什么Svg路径出现在控制台中而不显示在屏幕上?

Java Jade:不显示在控制台中

为什么我对 printf() 的调用不能在控制台中显示正确的字符?

为什么我无法在开发者控制台中查看 fetch 的 Response 对象中的 json?

在 _spark_metadata 中什么也没找到

为什么在控制台中打印和在标签中显示文件内容之间存在差异

通过声明性映射创建模式:Base.metadata.create_all(engine) 不起作用

为什么在vite中不能使用reflect-metadata