Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18.5 - Problems Creating Database #331

Closed
1 of 10 tasks
bummmer opened this issue Aug 2, 2020 · 2 comments
Closed
1 of 10 tasks

18.5 - Problems Creating Database #331

bummmer opened this issue Aug 2, 2020 · 2 comments

Comments

@bummmer
Copy link

bummmer commented Aug 2, 2020

Location within the Book

  • Book build date (Is the date on page 1): 2020-07-29
  • Book format (PDF, Epub or Mobi): PDF
  • Chapter or Appendix: 2
  • Section: 18
  • Subsection: 5
  • What operating system are you using:
    • Linux (Ubuntu 20.04)
    • Linux (Ubuntu 18.04)
    • Linux (Other)
    • MacOS Catalina
    • MacOS Mojave
    • MacOS Big Sur
    • Windows 10 Pro, Version 2004 or higher
    • Windows 10 Pro, Version 1909 or lower
    • Windows 10 Home, Version 2004 or higher
    • Windows 10 Home, Version 1909 or lower

Hint: Page numbers change all the time. The best way to report an issue is by chapter, section, and subsection numbers.

Description

At this point, using all defaults by cookiecutter, DATABASE_URL did not match what was generated in settings/base.py. The code in section 18.4 read:

DATABASES = {
# Raises ImproperlyConfigured Exception
# if DATABASE_URL Not in os.environ
"default": env.db(
    "DATABASE_URL",
    default="postgres://user:passwd@localhost:5432/everycheese"
    )
}

My default settings/base.py instead included:

"DATABASE_URL", default="postgres:///everycheese"

I didn't see anything mentioning changing defaults so I kept my above default and ran the following command from section 18.5:

python manage.py sqlcreate | sudo -u postgres psql -U postgres

It returned:

ERROR:  syntax error at or near "WITH"
LINE 1: CREATE USER  WITH ENCRYPTED PASSWORD '' CREATEDB;
                     ^
ERROR:  zero-length delimited identifier at or near """"
LINE 1: CREATE DATABASE everycheese WITH ENCODING 'UTF-8' OWNER "";
                                                                ^
ERROR:  syntax error at or near ";"
LINE 1: GRANT ALL PRIVILEGES ON DATABASE everycheese TO ;
                                                        ^

I replaced my default= with the example in the book:

default="postgres://user:passwd@localhost:5432/everycheese"

And again ran the command from 18.5. I received the following output this time:

ERROR:  syntax error at or near "user"
LINE 1: CREATE USER user WITH ENCRYPTED PASSWORD 'passwd' CREATEDB;
ERROR:  role "user" does not exist
ERROR:  syntax error at or near "user"
LINE 1: GRANT ALL PRIVILEGES ON DATABASE everycheese TO user;

I followed the Troubleshooting PostgreSQL: Role Does Not Exist (58.3) link and noticed that in the example error message an actual username, "audreyr" was used:

createdb: could not connect to database template1: FATAL:
role "audreyr" does not exist`

Before following the directions in 58.3 I changed settings/base.py again:

default="postgres://[actual_username]:[actual_password]@localhost:5432/everycheese"

Ran the command from 18.5 and received the following output:

python manage.py sqlcreate | sudo -u postgres psql -U postgres
CREATE ROLE
CREATE DATABASE
GRANT

Was then able to migrate and complete Section 18. Double-checked by following 16.6.1, Delete and Re-Clone.

Possible Solutions

This is my first time using PostgreSQL, so I'm not sure if my solution is correct. All I've discovered is the defaults in section 18.4 did not match the defaults when I created the project using cookiecutter. What I think the solution should be:

  1. cookiecutter template may need to be changed to match the code in 18.4 or, maybe there is an issue in section 16.4.2 where the reader is instructed to accept all defaults.

  2. Reader should be instructed to change "user:passwd" to an actual username and password?

Your full name so we can provide accurate credit within the book

Jeff Robinson

@luzfcb
Copy link
Contributor

luzfcb commented Aug 2, 2020

@bummmer Thanks to open a issue.

Please, check if the instructions of #320 (comment) work for you.

@bummmer
Copy link
Author

bummmer commented Aug 2, 2020

The instructions from #320 worked, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants