Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

python - Getting a typeError error in django project

I created a virtual environment for my new project, installed django and started the new project. However, whenever i run a line of code with manage.py i get this long error.

PS D:My stuffWebsite developmentIsow websiteisow> python manage.py makemigrations
No changes detected
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangocoremanagement\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangocoremanagement\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangocoremanagementase.py", line 336, in run_from_argv
    connections.close_all()
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangodbutils.py", line 224, in close_all
    connection.close()
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangodbackendssqlite3ase.py", line 248, in close
    if not self.is_in_memory_db():
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangodbackendssqlite3ase.py", line 367, in is_in_memory_db
    return self.creation.is_in_memory_db(self.settings_dict['NAME'])
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangodbackendssqlite3creation.py", line 12, in is_in_memory_db
    return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable

Database Entry:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It does seem NAME is being converted to pathlib.Path (WindowsPath) object instead of string which then cannot be used in Django in same way as os.path expects strings (Not 100% sure as did not investigate in depth)

So casting in string would be appropriate

'NAME': str(os.path.join(BASE_DIR, "db.sqlite3"))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...