SQLAlchemy no password supplied error

后端 未结 4 537
情话喂你
情话喂你 2020-12-23 16:27

This is probably a silly error but I cannot seem to find a satisfying solution.

When running db.create_all(), I got the following error.



        
相关标签:
4条回答
  • 2020-12-23 16:50

    On your Mac, PostgreSQL was set up for trust or peer authentication for connections from localhost.

    On your Ubuntu box it's set up for md5 authentication for connections from localhost.

    You'll want to configure a password, or change the authentication mode. See pg_hba.conf, and the Ubuntu guide for PostgreSQL (there's a section about this error).

    0 讨论(0)
  • 2020-12-23 16:54

    URL pattern should be:

    postgresql://user:password@localhost:5432/database_name
    

    pip install psycopg2
    the user should be postgres or any other user you have created and intend to use

    similarly for mySql it would be:

    mysql://user:pass@localhost:3306/database_name
    

    pip install mysql-python

    0 讨论(0)
  • 2020-12-23 16:56

    Below worked for me. Your connection to your postgres database requires a password; thus, below is what you should write..

    pg_user = "magicmike"
    pg_pwd = "test123"
    pg_port = "5432"
    app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://{username}:{password}@localhost:{port}/foodversity_db".format(username=pg_user, password=pg_pwd, port=pg_port)
    
    0 讨论(0)
  • 2020-12-23 16:59

    You probably just need to remove "localhost" from your connection string:

    'postgresql:///db_name'
    

    That tells psycopg2 to use Unix-domain sockets. Your default configuration will use "ident" so you'll be connecting as the user that runs the script. In the default configuration, "md5" only applies to TCP connections.

    0 讨论(0)
提交回复
热议问题