草庐IT

unique_schema_migrations

全部标签

python - 如何使用 Django migrate 命令跳过迁移?

首先,我问的是1.7中引入的Django迁移,而不是south。假设我有迁移001_add_field_x、002_add_field_y,并且它们都应用于数据库。现在我改变主意,决定恢复第二次迁移并用另一个迁移003_add_field_z替换它。也就是说,我想申请001和003,跳过002,怎么办?附:我知道我可以向后迁移到001,但是在我进行003迁移并执行迁移命令后,001到003将全部应用,对吗? 最佳答案 您可以使用--fake选项。一旦你恢复到0001你就可以运行pythonmanage.pymigrate0002--

python - Django:unique_together 是否以与 ForeignKey 相同的方式暗示 db_index=True?

模型上的一个字段,foo=models.ForeignKey(Foo)会自动为该列添加一个数据库索引,以加快查找速度。这很好,但是Django的文档没有说明模型元的unique_together中的字段是否接受相同的处理。我碰巧有一个模型,其中unique_together中列出的一个char字段需要一个索引以进行快速查找。我知道在字段定义中添加重复的db_index=True不会有什么坏处,但我很好奇。 最佳答案 如果有人来这里想知道除了unique_together是否还需要一个index_together来获得索引的性能优势,

python - django.db.utils.IntegrityError : duplicate key value violates unique constraint "django_content_type_pkey"

遇到了一点问题,当我运行“pythonmanage.pysyncdb”时,我收到了上述错误消息,我在一个相当旧的站点上工作。它使用postgresDB运行django1.2.6。运行没有安装南,我设法让它工作。Ranpythonmanage.pyschemamigration--initialcontact_enquiries运行良好并要求我迁移。然后我运行pythonmanage.pymigratecontact_enquiries然后我得到了和上面一样的错误。它没有提示我的模型中的任何语法,这就是我感到困惑的原因。这是我的模型,希望能有所启发。fromdjango.dbimport

python - Django:如何覆盖 unique_together 错误消息?

在模型的Meta类中,我定义了一个unique_together。我有一个基于这个模型的ModelForm。当我在此ModelForm上调用is_valid时,如果unique_together验证失败,将自动引发错误。这一切都很好。现在我的问题是我对默认的unique_together错误消息不满意。我想覆盖它。我怎样才能做到这一点?对于与字段相关的错误,我可以通过在字段参数上设置error_messages轻松做到这一点。但是unique_together是一个非字段错误。如何覆盖非字段错误消息? 最佳答案 你可以做this从D

python - Flask-Migrate 不创建表

我在文件listpull/models.py中有以下模型:fromdatetimeimportdatetimefromlistpullimportdbclassJob(db.Model):id=db.Column(db.Integer,primary_key=True)list_type_id=db.Column(db.Integer,db.ForeignKey('list_type.id'),nullable=False)list_type=db.relationship('ListType',backref=db.backref('jobs',lazy='dynamic'))rec

python - 从 DynamoDB 获取项目时出现 "The provided key element does not match the schema"错误

这是表分区键设置表格内容当我尝试从表中获取项目时,它会打印此错误botocore.exceptions.ClientError:Anerroroccurred(ValidationException)whencallingtheGetItemoperation:Theprovidedkeyelementdoesnotmatchtheschema这是我的代码dynamodb=boto3.resource('dynamodb')table=dynamodb.Table('testDynamodb')response=table.get_item(Key={'userId':"user287

python - Django 1.8 migrate 没有创建表

yekabathula-macbookair2:rosteryekabathula$pythonmanage.pymigrateOperationstoperform:Synchronizeunmigratedapps:staticfiles,messagesApplyallmigrations:admin,contenttypes,api,auth,sessionsSynchronizingappswithoutmigrations:Creatingtables...RunningdeferredSQL...InstallingcustomSQL...Runningmigration

python - Django: 'unique_together' 和 'blank=True'

我有一个看起来像这样的Django模型:classMyModel(models.Model):parent=models.ForeignKey(ParentModel)name=models.CharField(blank=True,max_length=200)...otherfields...classMeta:unique_together=("name","parent")这按预期工作;如果在同一个parent中有多次相同的name则我收到错误消息:“具有此名称和父项的MyModel已存在。”但是,当我保存多个具有相同parent但name字段为空白的MyModel时,我也会收

python - Boost.Python:如何公开 std::unique_ptr

我对boost.python还很陌生,并试图将函数的返回值公开给python。函数签名如下所示:std::unique_ptrsomeFunc(conststd::string&str)const;在python中调用函数时,出现如下错误:TypeError:Noto_python(by-value)converterfoundforC++type:std::unique_ptr>我在python中的函数调用如下所示:a=mymodule.MyClass()a.someFunc("somestringhere")#errorhere我试图公开std::unique_ptr但无法让它工作

python - Django unique_together 不防止重复

我显然不明白如何正确地做到这一点,有人可以让我直截了当。这是模型:classTeam(models.Model):teamID=models.CharField(max_length=255)#thiswillbegeneratedontheiPadname=models.CharField(max_length=255)slug=models.SlugField(max_length=50)teamNumber=models.CharField(max_length=30)checkIn=models.DateTimeField(default=datetime.now())tota