AttributeError:“元组”对象在开始迁移时没有属性“startswith”
Posted
技术标签:
【中文标题】AttributeError:“元组”对象在开始迁移时没有属性“startswith”【英文标题】:AttributeError: 'tuple' object has no attribute 'startswith' when start migrate 【发布时间】:2019-07-06 22:32:54 【问题描述】:我进行了 makemigrations,然后我使用了 migrate。 但它会导致下一个错误:AttributeError: 'tuple' object has no attribute 'startswith'
我明白,它与令人困惑的字符串和大量链接,但是如何解决它?有当renterinfo.0001_initial开始迁移 这是我的renterinfo.0001_initial 文件:
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Addresses',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id_renter', models.IntegerField()),
('subject', models.IntegerField()),
('city', models.CharField(blank=True, max_length=50, null=True)),
('street', models.CharField(blank=True, max_length=50, null=True)),
('house', models.CharField(blank=True, max_length=4, null=True)),
('housing', models.CharField(blank=True, max_length=3, null=True)),
('building', models.CharField(blank=True, max_length=2, null=True)),
('office', models.CharField(blank=True, max_length=3, null=True)),
('telephon', models.CharField(blank=True, max_length=16, null=True)),
('type', models.TextField(blank=True, null=True)),
],
options=
'db_table': ('renterinfo_addresses',),
'managed': True,
,
),
migrations.CreateModel(
name='IndEntrep',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('org_prav_form', models.TextField()),
('inn', models.CharField(max_length=12)),
('account_name', models.CharField(max_length=20)),
('acc_pwd', models.CharField(blank=True, max_length=128, null=True)),
('second_name', models.CharField(max_length=40)),
('first_name', models.CharField(max_length=40)),
('patronymic', models.CharField(max_length=40)),
('identity_doc', models.CharField(max_length=40)),
('serial_doc', models.CharField(max_length=8)),
('number_doc', models.CharField(max_length=8)),
('ogrnip', models.CharField(blank=True, max_length=15, null=True)),
],
options=
'db_table': ('renterinfo_indentrep',),
'managed': True,
,
),
migrations.CreateModel(
name='LegalDocuments',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=40, null=True)),
],
options=
'db_table': ('renterinfo_legaldocuments',),
'managed': True,
,
),
migrations.CreateModel(
name='Organizations',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('org_prav_form', models.TextField()),
('inn', models.CharField(max_length=12)),
('account_name', models.CharField(max_length=20)),
('acc_pwd', models.CharField(blank=True, max_length=128, null=True)),
('name', models.CharField(blank=True, max_length=50, null=True)),
('snameplp', models.CharField(blank=True, max_length=80, null=True)),
('fnameplp', models.CharField(blank=True, max_length=80, null=True)),
('patronymicplp', models.CharField(blank=True, max_length=80, null=True)),
('position', models.CharField(blank=True, max_length=80, null=True)),
('ogrn', models.CharField(blank=True, max_length=13, null=True)),
('identity_doc', models.CharField(blank=True, max_length=40, null=True)),
('serial_doc', models.CharField(blank=True, max_length=8, null=True)),
('number_doc', models.CharField(blank=True, max_length=8, null=True)),
('leg_docum', models.ForeignKey(blank=True, db_column='leg_docum', null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='renterinfo.LegalDocuments')),
],
options=
'db_table': ('renterinfo_organizations',),
'managed': True,
,
),
migrations.CreateModel(
name='Osnovanie',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=100, null=True)),
],
options=
'db_table': ('renterinfo_osnovanie',),
'managed': True,
,
),
migrations.CreateModel(
name='Persons',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('org_prav_form', models.TextField()),
('inn', models.CharField(max_length=12)),
('account_name', models.CharField(max_length=20)),
('acc_pwd', models.CharField(blank=True, max_length=128, null=True)),
('second_name', models.CharField(max_length=40)),
('first_name', models.CharField(max_length=40)),
('patronymic', models.CharField(max_length=40)),
('identity_doc', models.CharField(max_length=40)),
('serial_doc', models.CharField(max_length=8)),
('number_doc', models.CharField(max_length=8)),
('ogrnip', models.CharField(blank=True, max_length=15, null=True)),
],
options=
'db_table': ('renterinfo_persons',),
'managed': True,
,
),
migrations.CreateModel(
name='Positions',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=80, null=True)),
],
options=
'db_table': ('renterinfo_positions',),
'managed': True,
,
),
migrations.CreateModel(
name='Projects',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('id_renter', models.BigIntegerField(blank=True, null=True)),
('num_proj', models.CharField(blank=True, max_length=80, null=True)),
('date_project', models.DateField(blank=True, null=True)),
('date_zakl', models.DateField(blank=True, null=True)),
],
options=
'db_table': ('renterinfo_projects',),
'managed': True,
,
),
migrations.CreateModel(
name='Renters',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('org_prav_form', models.TextField()),
('inn', models.CharField(max_length=12)),
('account_name', models.CharField(max_length=20, unique=True)),
('acc_pwd', models.CharField(blank=True, max_length=128, null=True)),
],
options=
'db_table': ('renterinfo_renters',),
'managed': True,
,
),
migrations.CreateModel(
name='Viddoc',
fields=[
('id', models.IntegerField(primary_key=True, serialize=False)),
('type', models.TextField(blank=True, null=True)),
],
options=
'db_table': ('renterinfo_viddoc',),
'managed': True,
,
),
]
UPDmodels.py:
from django.db import models
class Addresses(models.Model):
id_renter = models.IntegerField()
subject = models.IntegerField()
city = models.CharField(max_length=50, blank=True, null=True)
street = models.CharField(max_length=50, blank=True, null=True)
house = models.CharField(max_length=4, blank=True, null=True)
housing = models.CharField(max_length=3, blank=True, null=True)
building = models.CharField(max_length=2, blank=True, null=True)
office = models.CharField(max_length=3, blank=True, null=True)
telephon = models.CharField(max_length=16, blank=True, null=True)
type = models.TextField(blank=True, null=True) # This field type is a guess.
class Meta:
managed = False
db_table = 'renterinfo_addresses',
managed = True
class IndEntrep(models.Model):
id = models.AutoField(primary_key=True)
org_prav_form = models.TextField() # This field type is a guess.
inn = models.CharField(max_length=12)
account_name = models.CharField(max_length=20)
acc_pwd = models.CharField(max_length=128, blank=True, null=True)
second_name = models.CharField(max_length=40)
first_name = models.CharField(max_length=40)
patronymic = models.CharField(max_length=40)
identity_doc = models.CharField(max_length=40)
serial_doc = models.CharField(max_length=8)
number_doc = models.CharField(max_length=8)
ogrnip = models.CharField(max_length=15, blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_indentrep',
managed = True
class LegalDocuments(models.Model):
name = models.CharField(max_length=40, blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_legaldocuments',
managed = True
class Organizations(models.Model):
id = models.AutoField(primary_key=True)
org_prav_form = models.TextField() # This field type is a guess.
inn = models.CharField(max_length=12)
account_name = models.CharField(max_length=20)
acc_pwd = models.CharField(max_length=128, blank=True, null=True)
name = models.CharField(max_length=50, blank=True, null=True)
snameplp = models.CharField(max_length=80, blank=True, null=True)
fnameplp = models.CharField(max_length=80, blank=True, null=True)
patronymicplp = models.CharField(max_length=80, blank=True, null=True)
position = models.CharField(max_length=80, blank=True, null=True)
leg_docum = models.ForeignKey(LegalDocuments, models.DO_NOTHING, db_column='leg_docum', blank=True, null=True)
ogrn = models.CharField(max_length=13, blank=True, null=True)
identity_doc = models.CharField(max_length=40, blank=True, null=True)
serial_doc = models.CharField(max_length=8, blank=True, null=True)
number_doc = models.CharField(max_length=8, blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_organizations',
managed = True
class Persons(models.Model):
id = models.AutoField(primary_key=True)
org_prav_form = models.TextField() # This field type is a guess.
inn = models.CharField(max_length=12)
account_name = models.CharField(max_length=20)
acc_pwd = models.CharField(max_length=128, blank=True, null=True)
second_name = models.CharField(max_length=40)
first_name = models.CharField(max_length=40)
patronymic = models.CharField(max_length=40)
identity_doc = models.CharField(max_length=40)
serial_doc = models.CharField(max_length=8)
number_doc = models.CharField(max_length=8)
ogrnip = models.CharField(max_length=15, blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_persons',
managed = True
class Positions(models.Model):
name = models.CharField(max_length=80, blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_positions',
managed = True
class Projects(models.Model):
id = models.BigAutoField(primary_key=True)
id_renter = models.BigIntegerField(blank=True, null=True)
num_proj = models.CharField(max_length=80, blank=True, null=True)
date_project = models.DateField(blank=True, null=True)
date_zakl = models.DateField(blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_projects',
managed = True
class Renters(models.Model):
org_prav_form = models.TextField() # This field type is a guess.
inn = models.CharField(max_length=12)
account_name = models.CharField(unique=True, max_length=20)
acc_pwd = models.CharField(max_length=128, blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_renters',
managed = True
class Viddoc(models.Model):
id = models.IntegerField(primary_key=True)
type = models.TextField(blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_viddoc',
managed = True
class Osnovanie(models.Model):
name = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'renterinfo_osnovanie',
managed = True
# Create your models here.
【问题讨论】:
添加您的模型。 @ShafikurRahman 我做到了。 【参考方案1】:您所有的db_table
选项都以逗号结尾,这会将它们变成元组。删除那些逗号。
db_table = 'renterinfo_addresses'
请注意,您需要删除并重新创建该迁移。
【讨论】:
以上是关于AttributeError:“元组”对象在开始迁移时没有属性“startswith”的主要内容,如果未能解决你的问题,请参考以下文章
AttributeError:“元组”对象没有属性“startswith”
model.fit AttributeError:“元组”对象没有属性“形状”
AttributeError:当向 Pytorch LSTM 网络提供输入时,“元组”对象没有属性“dim”
开始芹菜:AttributeError:“模块”对象没有属性“芹菜”