我有以下Django类:
class Contacto(models.Model):
responsable_documento = models.CharField(primary_key=True, max_length=40)
responsable_tipo_documento = models.CharField(max_length=20)
responsable_nombre = models.CharField(max_length=50, blank=True)
responsable_apellido = models.CharField(max_length=60, blank=True)
responsable_telefono = models.CharField(max_length=20, blank=True)
responsable_telefono_particular = models.CharField(max_length=20, blank=True)
responable_email_uno = models.EmailField()
responsable_email_dos = models.EmailField()
responsable_email_tres = models.EmailField()
cueanexo = models.PositiveIntegerField(null=True)
class Meta:
unique_together = (
('responsable_documento', 'responsable_tipo_documento', 'alumno_documento', 'alumno_tipo_documento'),
)
verbose_name_plural = 'contactos'
Run Code Online (Sandbox Code Playgroud)
我正在尝试重命名一些字段:
class Contacto(models.Model):
responsable_documento = models.CharField(primary_key=True, max_length=40)
responsable_tipo_documento = models.CharField(max_length=20)
responsable_nombre = models.CharField(max_length=50, blank=True)
responsable_apellido = models.CharField(max_length=60, blank=True)
responsable_telefono = models.CharField(max_length=20, blank=True)
responsable_telefono_celular = models.CharField(max_length=20, blank=True)
responable_email1 = models.EmailField() …Run Code Online (Sandbox Code Playgroud) 我在 MariaDB 中创建多对多关系表时遇到问题。我尝试过使用工作台、手动创建脚本和“Show Create Table xxxxxxx;” 从另一个已经创建的n到n个表但结果总是相同的,出现以下错误:
Error Code: 1005. Can't create table `asi_234_api_establecimientos`.`oe_modalidad` (errno: 150 "Foreign key constraint is incorrectly formed")
Run Code Online (Sandbox Code Playgroud)
我用来创建表的代码:
CREATE TABLE `oe_modalidad` (
`oferta_establecimiento_id` bigint(20) NOT NULL,
`modalidad_id` bigint(20) NOT NULL,
KEY `fk_oe_modalidades_oferta_establecimiento1_idx` (`oferta_establecimiento_id`),
KEY `fk_oe_modalidad_modalidad1_idx` (`modalidad_id`),
CONSTRAINT `fk_oe_modalidad_modalidad1` FOREIGN KEY (`modalidad_id`) REFERENCES `modalidad` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_oe_modalidades_oferta_establecimiento1` FOREIGN KEY (`oferta_establecimiento_id`) REFERENCES `oferta_establecimiento` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB
Run Code Online (Sandbox Code Playgroud)
我尝试在两个不同版本的 MariaDB(10.0.38 和 5.5.60)中运行它,但我不断收到相同的错误。
django ×1
django-2.0 ×1
foreign-keys ×1
mariadb ×1
migration ×1
mysql ×1
python ×1
python-3.x ×1
sql ×1