我有一个模型,其中的price是一个整数场。我确实进行了迁移,一切都很好。
from django.db import models
class Bill(models.Model):
price= models.IntegerField()
然后,由于需求变化,我不得不将price字段设置为JSONField,它将根据类似于此的某些键存储price值。
price={"actual_price":100, "tax_price":20}
我在模型中做了如下修改:
from django.db import models
class Bill(mod
我有一个django 1.5应用程序,现在我将它迁移到django 1.7,并且应用程序在旧数据库中运行良好。但是现在我希望使用django 1.7为该应用程序创建迁移。
我删除了旧的迁移,只保留了带有__ init__文件的迁移文件夹。
然后我运行了./manage.py makemigrations
在运行./manage.py migrate时,会产生一些错误。
django.db.utils.ProgrammingError: relation "django_site" does not exist
LINE 1: SELECT (1) AS "a"
我是Django开发的新手。我正在使用一个用MySQL创建的遗留数据库。现在我面临着Django迁移的问题。我有几个表使用外键来引用另一个表。现在,如果我允许Django使用外键管理这些表,那么Django会在make- migrate和migrate命令期间尝试重新创建外键字段。即使字段已经存在。除此之外,如果我不允许Django管理这些表,Django可以完美地与数据库一起工作。
我的代码适用于面向表格的错误
Models.py
from django.db import models
from django.utils.translation import gettext_lazy as
使用django-pgcrypto- field添加新字段后发生迁移错误
我的模型(第一次可以正常迁移)
class Dkm(models.Model):
name = fields.TextPGPSymmetricKeyField()
value = fields.IntegerPGPSymmetricKeyField(default=0)
我更新模型并再次迁移:
class Dkm(models.Model):
name = fields.TextPGPSymmetricKeyField()
value = fields.IntegerPGPSymmetri
与正常迁移不同,这是另一种迁移。我删除了整个项目和数据库。使用了一个基本的Django项目,其中没有任何应用程序。错误总是指向我以前的迁移。以确保我使用了默认的SQL。
导致此错误的步骤:我尝试使用add_to_class和contribute_to_class方法向Group添加列。在这样做的过程中,我失去了迁移的痕迹。
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001E7701610D0>
Traceback (most rec
我正在尝试在django_comment模型中添加一个新字段。根据文档,大多数自定义注释模型都会继承CommentAbstractModel模型:
from django.db import models
from django_comments.models import CommentAbstractModel
class CommentWithTitle(CommentAbstractModel):
title = models.CharField(max_length=300)
如果我生成一个迁移,那么它会将所有字段添加到迁移中(来自注释模型的所有字段加上标题字段)。
运行迁移
该项目位于django中,在SQLite中运行良好,但是当迁移到PostgreSQL并尝试注册时,用户将显示此错误。
File "C:\Users\liz\developer\env\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: the value is too long for varchar type varying(30)
已经将弹格字段更改为255
上周,我将一个新版本推到了一个服务器上,其中包括了一个新表的数据库迁移。这完成了预期的工作,但现在在每一个部署,当服务器运行它的迁移,我看到没有迁移应用,但也是一个独特的关键错误的内容类型;
Running migrations:
No migrations to apply.
...
File "/var/www/django/myproj/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
我正在和另一个开发人员一起开发Django应用程序。到目前为止我爱Django。
但是,为了能够在开发过程中修改models.py,我找到了一个south的副本,现在我们一直在进行迁移合并冲突。
是的,我已经收到备忘录了:
The important message here is that South is no substitute for team coordination - in fact, most
of the features are there purely to warn you that you haven’t coordinated, and the simple m
我一直在使用django迁移来处理数据库。最近,我把会议分成两个部分,一个是阅读,另一个是写作。完成此操作后,我创建了新的迁移文件,该文件添加了新表并运行它。很成功,
Operations to perform:
Apply all migrations: food
Running migrations:
Applying food.0107_auto_20171116_0849... OK
但是,当我使用shell检查mysql数据库时,没有新的表。我删除了django迁移历史,并尝试了几次,但结果是一样的。它说迁移应用了,但是没有新的表格。这是我的迁移文件
# -*- coding: ut
我有一个django项目,带有数据库迁移。
MyModel.my_field表示模型MyModel上的DateTimeField
初始迁移的初始日期时间为默认值(即datetime.datetime.now)。
一种新的迁移现在将其命名为django.utils.timezone.now
我不加载任何固定装置作为迁移的一部分
每当我测试这个项目时,我都会收到这个警告。
.../django/db/models/fields/__init__.py:1474: RuntimeWarning: DateTimeField MyModel.my_field received a naive date