我一直在本地计算机上工作,最近我在现有模型中添加了一些字段。
今天早上我试图在Heroku上推送它并进行迁移,这是我得到的消息:
我的模型。py
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 = models.TextField(verbose_name="Description supplémentaire",null=True, blank=True)
date_posted = models.DateTimeField(default=timezone.now)
complete = models.BooleanField(default=False)
recurrence = models.BooleanField(default=False)
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')
Todo.reccurence是新字段。
跟踪:
Environment:
Request Method: GET
Request URL:
Django Version: 2.1.7
Python Version: 3.6.7
Installed Applications:
['blog.apps.BlogConfig',
'dashboard.apps.DashboardConfig',
'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']
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']
Template error:
In template /app/blog/templates/blog/base.html, error at line 0
column dashboard_todo.recurrence does not exist
LINE 1: ...todo"."date_posted", "dashboard_todo"."complete", "dashboard...
^
1 : {% load crispy_forms_tags %}
2 : <!DOCTYPE html>
3 : <html>
4 : <head>
5 :
6 : <!-- Global site tag (gtag.js) - Google Analytics -->
7 : <script async src="https://www.googletagmanager.com/gtag/js?id=UA-134278636-1"></script>
8 : <script>
9 : window.dataLayer = window.dataLayer || [];
10 : function gtag(){dataLayer.push(arguments);}
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 (column dashboard_todo.recurrence does not exist
LINE 1: ...todo"."date_posted", "dashboard_todo"."complete", "dashboard...
^
) 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
156. 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
154. response = response.render()
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/response.py" in render
106. self.content = self.rendered_content
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/response.py" in rendered_content
83. content = template.render(context, self._request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py" in render
61. return self.template.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
171. return self._render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
150. return compiled_parent._render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
62. result = block.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/defaulttags.py" in render
166. len_values = len(values)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __len__
250. self._fetch_all()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all
1186. self._result_cache = list(self._iterable_class(self))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __iter__
54. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
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 /
Exception Value: column dashboard_todo.recurrence does not exist
LINE 1: ...todo"."date_posted", "dashboard_todo"."complete", "dashboard...
^
我通常要做的是删除本地计算机上的数据库,然后再次运行migrate,但是我真的不能用真实数据做到这一点。
谢谢
答案 0 :(得分:1)
您不应该在Heroku上运行makemigrations。在本地进行操作,提交结果,然后在Heroku上运行迁移。