TypeError: argument of type 'PosixPath' is not iterabl
TypeError: argument of type 'PosixPath' is not iterabl
请帮助我从 python manage.py makemigrations
得到这个错误
Migrations for 'post': post/migrations/0022_auto_20200929_1749.py
- Remove field category from post
- Remove field tag from post Traceback (most recent call last): File "manage.py", line 22, in
main() File "manage.py", line 18, in main
execute_from_command_line(sys.argv) File "/usr/lib/python3.8/site-packages/django/core/management/init.py",
line 381, in execute_from_command_line
utility.execute() File "/usr/lib/python3.8/site-packages/django/core/management/init.py",
line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python3.8/site-packages/django/core/management/base.py",
line 336, in run_from_argv
connections.close_all() File "/usr/lib/python3.8/site-packages/django/db/utils.py", line 224, in
close_all
connection.close() File "/usr/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py",
line 248, in close
if not self.is_in_memory_db(): File "/usr/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py",
line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME']) File
"/usr/lib/python3.8/site-packages/django/db/backends/sqlite3/creation.py",
line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name TypeError: argument of type 'PosixPath' is not iterabl
models.py
来自 django.db 导入模型
> # Create your models here. from django.db import models from django.utils import timezone
>
>
> class Post(models.Model):
> author = models.ForeignKey('auth.User', on_delete=models.CASCADE ,null=True)
> title = models.CharField(max_length=200,null=True)
> description=models.TextField(default='a')
> text = models.TextField(null=True)
> Img = models.ImageField(upload_to='images/',null =True)
> UserImg= models.ImageField(upload_to='images/user/',null =True)
>
> created_date = models.DateTimeField(
> default=timezone.now)
> published_date = models.DateTimeField(
> blank=True, null=True)
>
> def publish(self):
> self.published_date = timezone.now()
> self.save()
>
> def __str__(self):
> return self.title
> def approved_comments(self):
> return self.comments.filter(approved_comment=True)
>
> class Comment(models.Model):
> post = models.ForeignKey('post.Post', on_delete=models.CASCADE, related_name='comments')
> name = models.CharField(max_length=200)
> text = models.TextField()
> email=models.EmailField(null=True)
> created_date = models.DateTimeField(default=timezone.now)
> approved_comment = models.BooleanField(default=False)
>
> def approve(self):
> self.approved_comment = True
> self.save()
>
> def __str__(self):
> return self.text
这个错误有点歪曲,告诉它删除一个 field
一个不存在的(或者以前可能存在的)但是在进行迁移时不应该是错误的原因。
Migrations for 'post': post/migrations/0022_auto_20200929_1749.py - Remove field category from post - Remove field tag from post Traceback
如果我是对的,您可能正在使用 Django 3.1
,这将 BASE_DIR pseudo-setting 移动为使用 pathlib.Path
而不是纯字符串。对此的支持需要在某些地方添加 str()
,例如 sqlite 驱动程序。
如果您查看设置文件中 BASE_DIR 的定义,它是否使用 Path() ?如果是这样,您可以在 DATABASES 设置中使用 str(),即 str(BASE_DIR / "something.sqlite")
.
阅读此处了解更多信息 - Use Pathlib in Your Django Settings File
请帮助我从 python manage.py makemigrations
得到这个错误Migrations for 'post': post/migrations/0022_auto_20200929_1749.py - Remove field category from post - Remove field tag from post Traceback (most recent call last): File "manage.py", line 22, in main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/usr/lib/python3.8/site-packages/django/core/management/init.py", line 381, in execute_from_command_line utility.execute() File "/usr/lib/python3.8/site-packages/django/core/management/init.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python3.8/site-packages/django/core/management/base.py", line 336, in run_from_argv connections.close_all() File "/usr/lib/python3.8/site-packages/django/db/utils.py", line 224, in close_all connection.close() File "/usr/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 248, in close if not self.is_in_memory_db(): File "/usr/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 367, in is_in_memory_db return self.creation.is_in_memory_db(self.settings_dict['NAME']) File "/usr/lib/python3.8/site-packages/django/db/backends/sqlite3/creation.py", line 12, in is_in_memory_db return database_name == ':memory:' or 'mode=memory' in database_name TypeError: argument of type 'PosixPath' is not iterabl
models.py 来自 django.db 导入模型
> # Create your models here. from django.db import models from django.utils import timezone
>
>
> class Post(models.Model):
> author = models.ForeignKey('auth.User', on_delete=models.CASCADE ,null=True)
> title = models.CharField(max_length=200,null=True)
> description=models.TextField(default='a')
> text = models.TextField(null=True)
> Img = models.ImageField(upload_to='images/',null =True)
> UserImg= models.ImageField(upload_to='images/user/',null =True)
>
> created_date = models.DateTimeField(
> default=timezone.now)
> published_date = models.DateTimeField(
> blank=True, null=True)
>
> def publish(self):
> self.published_date = timezone.now()
> self.save()
>
> def __str__(self):
> return self.title
> def approved_comments(self):
> return self.comments.filter(approved_comment=True)
>
> class Comment(models.Model):
> post = models.ForeignKey('post.Post', on_delete=models.CASCADE, related_name='comments')
> name = models.CharField(max_length=200)
> text = models.TextField()
> email=models.EmailField(null=True)
> created_date = models.DateTimeField(default=timezone.now)
> approved_comment = models.BooleanField(default=False)
>
> def approve(self):
> self.approved_comment = True
> self.save()
>
> def __str__(self):
> return self.text
这个错误有点歪曲,告诉它删除一个 field
一个不存在的(或者以前可能存在的)但是在进行迁移时不应该是错误的原因。
Migrations for 'post': post/migrations/0022_auto_20200929_1749.py - Remove field category from post - Remove field tag from post Traceback
如果我是对的,您可能正在使用 Django 3.1
,这将 BASE_DIR pseudo-setting 移动为使用 pathlib.Path
而不是纯字符串。对此的支持需要在某些地方添加 str()
,例如 sqlite 驱动程序。
如果您查看设置文件中 BASE_DIR 的定义,它是否使用 Path() ?如果是这样,您可以在 DATABASES 设置中使用 str(),即 str(BASE_DIR / "something.sqlite")
.
阅读此处了解更多信息 - Use Pathlib in Your Django Settings File