0

Trying to use Heroku and deploy a project using Postgres..as Heroku only generates Database_URL with Postgres and not PostgreSQL tried the below code suggested by the Heroku community but it is throwing above mentioned error.

uri = os.environ.get("DATABASE_URL")  # or other relevant config var

if uri.startswith("postgres://"):
    uri = uri.replace("postgres://", "postgresql://", 1)

error " if uri.startswith("postgres://"): AttributeError: 'NoneType' object has no attribute 'startswith' "

  • If `DATABASE_URL` is not a set variable, `os.environ.get("DATABASE_URL")` will return `None` rather than a string. That seems to be what happened to you, because your error message tells you that uri is "`NoneType`"; and if that's the case, nothing you try to do with it afterward will work. – codingatty Jul 26 '22 at 20:19
  • @codingatty The Database_URL is by default set in Heroku Config Vars settings. I am just trying to use it but if I use the DATABASE_URL directly it i s throwing this error: "sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres " So I checked for solutions and found the above one ....but that is also throwing an error...Here is the link https://stackoverflow.com/questions/62688256/sqlalchemy-exc-nosuchmoduleerror-cant-load-plugin-sqlalchemy-dialectspostgre – emma thompson Jul 26 '22 at 20:32
  • I'm telling you it appears to me that `DATABASE_URL` is not actually set, even though you expect it to be. Try printing `os.environ`, and see if it has a key named `DATABASE_URL`. I'm betting you find it doesn't. If it doesn't, your `os.environ.get("DATABASE_URL")` will return `None` and nothing after that will work correctly for you. – codingatty Jul 26 '22 at 21:01

0 Answers0