gpt4 book ai didi

python - 关系不存在 - Django 和 Postgres

转载 作者:行者123 更新时间:2023-11-29 12:40:04 26 4
gpt4 key购买 nike

我在现有模型中添加了一些表,但是当我将我的项目推送到 heroku 时出现错误:

我在这个特定应用程序上添加的任何模型都会发生这种情况

ProgrammingError at /admin/dashboard/adressbook/ relation "dashboard_adressbook" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "dashboard_adressbook"

我的模型.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 上进行了迁移。

谢谢

最佳答案

警告: 请不要犯同样的错误,不要在本地机器和生产环境中使用不同的引擎,一旦遇到问题,就无法修复

所以 4 天后,我通过从数据库中删除数据解决了这个问题。

我开始清理并确保在推送到 heroku 之前迁移,我也一直在使用相同的引擎 (postgres)在我的本地机器和 Heroku 上,到目前为止我还没有遇到任何错误。

所以要解决这个问题就得从头开始,唯一的解决办法就是删除数据库,如果你有有值(value)的数据,这就不太方便了。

关于python - 关系不存在 - Django 和 Postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55117984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com