sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)设置我的数据库时

时间:2019-04-25 20:57:45

标签: postgresql sqlalchemy vagrant psycopg2

我正在尝试通过运行以下python代码来建立新的数据库,但其标题中显示了该错误

import os import sys from sqlalchemy import Column, ForeignKey, Integer, String from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship from sqlalchemy import create_engine

Base = declarative_base()

class Restaurant(Base): __tablename__ = 'restaurant'

id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)

class MenuItem(Base): __tablename__ = 'menu_item'

name =Column(String(80), nullable = False)
id = Column(Integer, primary_key = True)
description = Column(String(250))
price = Column(String(8))
course = Column(String(250))
restaurant_id = Column(Integer,ForeignKey('restaurant.id'))
restaurant = relationship(Restaurant) 

engine = create_engine('sqlite:///restaurantmenu.db')

我将代码的最后一行编辑为: engine = create_engine('postgresql+psycopg2://vagrant:vagrant@localhost/restaurantmenu') 我也尝试了我的PC密码和用户名,但无论如何还是出现以下错误:

  

文件“ /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py”,>行453,在connect中      返回self.dbapi.connect(* cargs,** cparams)   连接中的文件“ /usr/local/lib/python2.7/dist-packages/psycopg2/init.py”,行> 130     conn = _connect(dsn,connection_factory = connection_factory,** kwasync)   sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)严重:用户“ vagrant”的密码>身份验证失败   严重:用户“无业游民”的密码身份验证失败

运行命令时,我希望该文件创建一个新的restaurant.db文件 vagrant @ vagrant $ python database_setup.py

要成功运行该代码,我还需要更改什么?

0 个答案:

没有答案