【发布时间】:2020-06-23 16:34:07
【问题描述】:
我正在将我的 Django 应用程序从 Postgres 移植到 MariaDB,并在执行迁移步骤时收到以下错误:
django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[20] NOT NULL, `last_update` datetime(6) NOT NULL, `commited` bool NOT NULL, ...' at line 1")
创建了所有标准 Django 表,并创建了我的第一个模型表。但我永远不会超越那一步。
我的模特都是以下风格:
class Country(models.Model):
name = models.CharField(max_length=100, unique=True,
help_text=_('This is the full name of the country'),
verbose_name=_('Country'),
)
alternate_name = models.CharField(max_length=100, null=True, blank=True,
help_text=_('This is the alternate name - often abbreviation - of the country'),
verbose_name=_('Country alternate name'),
)
iso_numeric = models.DecimalField(max_digits=3, decimal_places=0,null=True,
help_text=_('This is the ISO numeric code of the country'),
verbose_name=_('ISO numeric code'),
)
iso_alpha = models.CharField(max_length=3, null=True, blank=True,
help_text=_('This is the ISO alpha code of the country'),
verbose_name=_('ISO alpha code'),
)
last_update = models.DateTimeField(auto_now_add=True,
help_text=_('This is the timestamp of the last update'),
verbose_name=_('Timestamp last update'),
)
last_update_id = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL, editable=False,
help_text=_('This is the user making last update'),
verbose_name=_('User making last update'),
)
committed = models.BooleanField(default=False, editable=False,
help_text=
_('This field is set to false once record is created until admin has committed it'),
verbose_name=_('Committed'),
)
我看到了可能涉及 DateTime 或 Boolean 字段的类似问题。但是,即使我将它们注释掉,我也会得到相同的结果。
玛丽亚数据库: MariaDB [(none)]> 状态
mysql Ver 15.1 Distrib 10.4.13-MariaDB,用于 osx10.15 (x86_64) 使用 readline 5.1
我正在使用 mysqlclient 1.4.6。
任何指针? 谢谢, 马丁
【问题讨论】:
-
[不是有效的 MySQL 字符。知道它是从哪里来的吗? -
不,您指的是哪个 ]?我的挑战是,这是生成的 SQL 代码,因此很难找到确切的错误。
-
正好指向
[20]。那是在输入中。什么在生成输入? -
所有文本字段均为 100。其余为十进制或布尔值。所以,我有点猜测它是 DateTimeField。 SQL 是从 Django 从 Python 模型文件中生成的。它可能与似乎对应于 MySQL 5.5 的 MariaDB 版本有关。但是我看不到升级的方法,因为没有更新的版本(至少对于 MacOS)。它适用于其他数据库,但我需要 MariaDB 作为我想要使用的云提供商。