Reputation: 81
I have created a new django proejct and the only modification I have made is to the settings, changing the database from sqlite to postgres:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': BASE_DIR / 'yachtdrop',
'USER': 'postgres',
'PASSWORD': 'passsword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
I am using pipenv to manage my virtual environment, my pipfile is as follows:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
django = "*"
requests = "*"
flask = "*"
psycopg2-binary = "*"
[dev-packages]
[requires]
python_version = "3.9"
When I write the command 'python manage.py runserver', the system returns 'TypeError: object of type 'WindowsPath' has no len()' and I don't understand why this is happening. I am running this on Windows. I have recently reset my Windows system and have a fresh installation of python, pipenv and postgres.
It would be great if anyone could help me out here. Thanks!
Upvotes: 8
Views: 7610
Reputation: 248
Django creates the db.sqllite3 file in the base directory by default but with other databases no need to use 'BASE_DIR' constant in the name. It will goto the host and look for the db file name you have given.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'yachtdrop',
'USER': 'postgres',
'PASSWORD': 'passsword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Upvotes: 22