mysql – 如何在django中的字段上进行数据库分区?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql – 如何在django中的字段上进行数据库分区?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2208字,纯文字阅读大概需要4分钟。
内容图文
![mysql – 如何在django中的字段上进行数据库分区?](/upload/InfoBanner/zyjiaocheng/893/086a2d054cb14052a91596afa5ae21dd.jpg)
我有多个字段的django模型,它被映射到MySQL数据库,现在模型中有一个日期时间字段,我想在其中设置partitioning.
该模型如下所示:
class Packet(models.Model):
device = models.ForeignKey(Device)
packet_time = models.DateTimeField(default=timezone.now())
# Location Details
signal = models.CharField(max_length=2, default='A')
lat = models.FloatField(default=None, null=True)
lat_indicator = models.CharField(max_length=1, default='')
lng = models.FloatField(default=None, null=True)
lng_indicator = models.CharField(max_length=1, default='')
address = models.CharField(max_length=64, default='NA')
speed = models.FloatField(default=None, null=True)
orientation = models.FloatField(default=None, null=True)
#House Keeping Items
dor = models.DateTimeField(default=timezone.now()) # <= Want to partition this for weekly basis.
dirty = models.BooleanField(default=False)
请告诉我如何实现这一目标.
解决方法:
正如Max的评论中所提到的,django-db-parti不赞成使用architech.Github链接可用于here,并在readthedocs提供了更多文档
原答案:
django-db-parti包存在,似乎符合您的标准. Github链接here.
该文档的MySQL部分指出:
MySQL’s partitioning implementation in Django DB Parti is done in a
mixed way, half at the python level and half at the database level.
Unfortunately MySQL doesn’t support dynamic sql in triggers or
functions that are called within triggers, so the only way to create
partitions automatically is to calculate everything at the python
level, then to create needed sql statements based on calculations and
issue that statement into the database.
并具有以下限制
- Not all partitioning types are supported. New types will be added in next releases of Django DB Parti.
- Partitioning is not available for bulk inserts (i.e. Django’s bulk_create() method) because it doesn’t call model’s save() method
which this backend relies on. Currently there is no known way to
remove this limitation.- New partitions can be created only from lower to higher, you can overcome this with MySQL’s special command REORGANIZE PARTITION which
you have to issue from the database console. You can read more about
it at the MySQL’s documentation. We plan to remove this limitation in
one of the future releases of Django DB Parti.
分区的configuration出现在模型的Meta类中.
内容总结
以上是互联网集市为您收集整理的mysql – 如何在django中的字段上进行数据库分区?全部内容,希望文章能够帮你解决mysql – 如何在django中的字段上进行数据库分区?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。