我在现有模型中添加了一些表格,但是当我将项目推送到heroku时却出现了错误:
在我添加到此特定应用的所有模型上都会发生这种情况
/ admin / dashboard / adressbook /中的ProgrammingError 关系“ dashboard_adressbook”不存在 第1行:从“ dashboard_adressbook”中选择COUNT(*)作为“ __count”
我的模型。py
class AdressBook(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="Nom de l'utilisateur")
text = models.CharField(max_length=200,verbose_name="Description")
number = models.CharField(max_length=20,verbose_name="Numéro de téléphone")
def __str__(self):
return self.text
def get_absolute_url(self):
return reverse('dashboard-home')
class Dashboard(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="Nom de l'utilisateur")
content = RichTextField(max_length=500,verbose_name="Description")
text = models.TextField(verbose_name="Description supplémentaire",null=True, blank=True)
date_posted = models.DateTimeField(default=timezone.now)
def __str__(self):
return self.content
def get_absolute_url(self):
return reverse('dashboard-home')
class Links(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE,verbose_name="Nom de l'utilisateur")
content = models.URLField(max_length=500, verbose_name="URL")
name = models.CharField(max_length=500, verbose_name="Description")
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('dashboard-home')
class Todo(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE,verbose_name="Nom de l'utilisateur")
text = models.CharField(max_length=150, verbose_name="Nom de la Todo")
content = RichTextField(verbose_name="Description supplémentaire",null=True, blank=True)
date_posted = models.DateTimeField(default=timezone.now)
complete = models.BooleanField(default=False, verbose_name="Statut de la Todo")
urgence = models.BooleanField(default=False,verbose_name="Tâche urgente")
def __str__(self):
return self.text
def get_absolute_url(self):
return reverse('dashboard-home')
class Phone(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="Nom de l'utilisateur")
text = models.CharField(max_length=200,verbose_name="Description")
number = models.CharField(max_length=20,verbose_name="Numéro de téléphone")
def __str__(self):
return self.text
def get_absolute_url(self):
return reverse('dashboard-home')
跟踪:
Django Version: 2.1.7
Python Version: 3.6.7
Installed Applications:
['blog.apps.BlogConfig',
'dashboard.apps.DashboardConfig',
'property.apps.PropertyConfig',
'users.apps.UsersConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'storages',
'cloudinary',
'ckeditor']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
The above exception (relation "dashboard_adressbook" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "dashboard_adressbook"
^
) was the direct cause of the following exception:
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
604. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
223. return view(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
45. return bound_method(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/admin/options.py" in changelist_view
1675. cl = self.get_changelist_instance(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/admin/options.py" in get_changelist_instance
742. sortable_by,
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/admin/views/main.py" in __init__
81. self.get_results(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/admin/views/main.py" in get_results
209. result_count = paginator.count
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py" in __get__
37. res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/paginator.py" in count
87. return self.object_list.count()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in count
383. return self.query.get_count(using=self.db)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_count
498. number = obj.get_aggregation(using, ['__count'])['__count']
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_aggregation
483. result = compiler.execute_sql(SINGLE)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
1065. cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
100. return super().execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
68. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
77. return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /admin/dashboard/adressbook/
Exception Value: relation "dashboard_adressbook" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "dashboard_adressbook"
^
我在本地计算机上进行了所有迁移,但问题仍然存在。
我也在Heroku上进行了迁移。
谢谢
答案 0 :(得分:1)
这对我有用
答案 1 :(得分:0)
所以4天后我解决了这个问题,但是从数据库中删除了仪表板中的数据。
我开始清理并确保在将其推送到heroku之前进行迁移,我也在本地计算机和Heroku上使用了相同的引擎(postgres),到目前为止,我还没有遇到任何错误。
答案 2 :(得分:0)
从Heroku仪表板重置数据库后,登陆模板从数据库获取数据时,我遇到了同样的错误。
我通过以下方法解决了该问题: