【问题标题】:Django syncdb AttributeError: 'list' object has no attribute 'startswith'Django syncdb AttributeError:“list”对象没有属性“startswith”
【发布时间】:2012-12-21 18:37:34
【问题描述】:

没有找到解决办法。

models.py

class Product(models.Model):
    prod_id = models.IntegerField(primary_key = True)
    prod_name = models.CharField(max_length=128)
    prod_price = models.FloatField()
    prod_quantity = models.CharField(max_length=75)
    prod_description = models.TextField()
    prod_attributes = models.TextField()
    prod_ingredients = models.TextField()

settings.py

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'MyApp',

这是抛出的错误:

创建表格 ... self.fetch_command(子命令).run_from_argv(self.argv) 文件“C:\Python27\Lib\site-packages\django\core\management\base.py”,第 196 行,在 run_from_argv self.execute(*args, **options.dict) 文件“C:\Python27\Lib\site-packages\django\core\management\base.py”,第 232 行,在执行中 输出 = self.handle(*args, **options) 文件“C:\Python27\Lib\site-packages\django\core\management\base.py”,第 371 行,在句柄中 返回 self.handle_noargs(**options) 文件“C:\Python27\Lib\site-packages\django\core\management\commands\syncdb.py”,第 91 行,在 handle_noargs sql, 参考 = connection.creation.sql_create_model(model, self.style, seen_models) sql_create_model 中的文件“C:\Python27\Lib\site-packages\django\db\backends\creation.py”,第 82 行 style.SQL_TABLE(qn(opts.db_table)) + ' ('] 文件“C:\Python27\Lib\site-packages\django\db\backends\mysql\base.py”,第 244 行,在 quote_name 如果 name.startswith("") and name.endswith(""): AttributeError: 'list' 对象没有属性 'startswith'

所以关键部分: AttributeError: 'list' 对象没有属性 'startswith'

有人对我为什么会收到此错误有任何想法吗?我已经尝试了很多不同的东西,即使它成功地创建了其他表,它也不会工作它只是不会创建我的模型类。我正在使用 mysql 数据库。

【问题讨论】:

    标签: mysql database django models syncdb


    【解决方案1】:

    回溯表明您可能错误地使用了db_table 选项。它应该是一个字符串,而不是一个列表。请检查您的使用情况,如果您不确定,请使用更多代码更新您的问题。

    【讨论】:

    • 我怎么看不到。正如你所说,我错误地使用了 db_table 选项。我将其更改为 Meta 类:db_table = u'Products'Thanks Alot Man
    猜你喜欢
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-11
    • 2013-07-29
    • 2017-10-05
    • 1970-01-01
    相关资源
    最近更新 更多