You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to configure my db with separate variables in .env.
I have the following:
DJANGO_DB_NAME=dbname
DJANGO_DB_USER=dbuser
DJANGO_DB_PASSWORD=dbpassword
First of all, if I define them in the DATABASES dictionary they are all None
I get an error saying "ValueError: Value 'DB_PASSWORD' is required to be set as the environment variable 'DJANGO_DB_PASSWORD'" although it's well defined. I have debuging to see if the .env file is loaded and at the end of the "load_dotenv" method is configurations/base.py all the variables are in os.environ.
Also, when I checked the values of NAME and USER, they are "None" instead of correct values.
Second, if I move the values outside of the dictionary as follows:
I get an error in "File "django/db/backends/postgresql/base.py", line 200, in get_connection_params" saying
"TypeError: object of type 'Value' has no len()"
The line in question is "if len(settings_dict["NAME"] or "") > self.ops.max_name_length():"
Again, debugging it, I can verify that type(settings_dict["NAME"]) is "configurations.Value"
The DB_USER and DB_PASSWORD don't seem to cause any issue.
For some unexplained reason, converting it to string as str(DB_NAME) does't work, since it gives me the string "none" as "NAME" in the dictionary.
Third, I tried using the DatabaseURLValue and it works, but when I try to add the "OPTIONS" key to the db dict in order to add the schema info, I get an error saying "*** TypeError: 'DatabaseURLValue' object is not subscriptable"
Here is the code :
DATABASES = values.DatabaseURLValue()
DATABASES["default"]["OPTIONS"] = values.DictValue(environ_name="DB_OPTIONS", environ_prefix=None)
Can you explain all the 3 issues I'm having ?
The text was updated successfully, but these errors were encountered:
BTW, I'm using successfully the 1st approach, where I define the variables in the dictionary itself, in a project in python 2.7, django 1.11.29 and django-configraitons 1.0
EDIT: I actually found a difference that in my project where I'm using the 1st approach. I'm not defining an attribute DATABASES, but a property as in
I'm using the lastest pypi version 2.5.
I'm trying to configure my db with separate variables in .env.
I have the following:
DJANGO_DB_NAME=dbname
DJANGO_DB_USER=dbuser
DJANGO_DB_PASSWORD=dbpassword
First of all, if I define them in the DATABASES dictionary they are all None
I get an error saying "ValueError: Value 'DB_PASSWORD' is required to be set as the environment variable 'DJANGO_DB_PASSWORD'" although it's well defined. I have debuging to see if the .env file is loaded and at the end of the "load_dotenv" method is configurations/base.py all the variables are in os.environ.
Also, when I checked the values of NAME and USER, they are "None" instead of correct values.
Second, if I move the values outside of the dictionary as follows:
I get an error in "File "django/db/backends/postgresql/base.py", line 200, in get_connection_params" saying
"TypeError: object of type 'Value' has no len()"
The line in question is "if len(settings_dict["NAME"] or "") > self.ops.max_name_length():"
Again, debugging it, I can verify that type(settings_dict["NAME"]) is "configurations.Value"
The DB_USER and DB_PASSWORD don't seem to cause any issue.
For some unexplained reason, converting it to string as str(DB_NAME) does't work, since it gives me the string "none" as "NAME" in the dictionary.
Third, I tried using the DatabaseURLValue and it works, but when I try to add the "OPTIONS" key to the db dict in order to add the schema info, I get an error saying "*** TypeError: 'DatabaseURLValue' object is not subscriptable"
Here is the code :
DATABASES = values.DatabaseURLValue()
DATABASES["default"]["OPTIONS"] = values.DictValue(environ_name="DB_OPTIONS", environ_prefix=None)
Can you explain all the 3 issues I'm having ?
The text was updated successfully, but these errors were encountered: