Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: 'python manage.py runserver' returns 'TypeError: object of type 'WindowsPath' has no len()'

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!

like image 738
Sebastian Strand Avatar asked Dec 30 '22 17:12

Sebastian Strand


1 Answers

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',
    }
}
like image 182
K.M.Jiaul Islam Jibon Avatar answered Jan 02 '23 07:01

K.M.Jiaul Islam Jibon