在Django mod中设置默认排序规则设置

2024-10-02 18:19:08 发布

您现在位置:Python中文网/ 问答频道 /正文

Django documentation表示默认排序规则为“utf8”,但事实并非如此。每次运行syncdb创建新表时,所有字符字段的默认排序规则都是“latin1_swedish_ci”。在

同样的文件也说

Django doesn’t provide a way to set this on the model definition.

有没有其他方法可以强制django的syncdb对字符字段使用特定的排序规则?在


Tags: 文件djangoci排序规则documentationutf8字符
1条回答
网友
1楼 · 发布于 2024-10-02 18:19:08

通常(要更改字符集和排序规则),可以使用迁移,例如:

# -*- coding: utf-8 -*-
# Generated by Django 1.11.10
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('some_model', 'A_previous_migration'),
    ]

    operations = [
        migrations.RunSQL('ALTER TABLE some_table CHANGE column_name column_name VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;'),
    ]

当然,你描述的行为是怪异的,所以也许有更好的方法来解决你的特定问题。在

相关问题 更多 >