<p>我有一个模型是这样的:</p>
<pre><code>class Base(models.Model):
pass
class Mixin1(Base):
active = models.BooleanField(default=False)
class Mixin2(Base):
name = models.CharField(max_length=200,blank=False,null=False)
class Organization(Mixin1, Mixin2, Base):
pass
</code></pre>
<p>这很好:</p>
^{pr2}$
<p>但这并不能:</p>
<pre><code>organization = Organization(name='name', active=True)
organization.save()
</code></pre>
<p>Django在构造函数上出错,错误为:</p>
<pre><code>TypeError: 'active' is an invalid keyword argument for this function
</code></pre>
<p>a关于混音我有什么遗漏吗?</p>
<p><strong>更新我看到的内容:</strong>
使用一个新的PostgreSQL数据库和一个新的shell。</p>
<pre><code>Python 2.7.3 (default, Sep 5 2012, 20:48:07)
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from core.models.organizations import Organization
>>> org1 = Organization(name='name')
>>> org1
<Organization: name>
>>> org1.active = True
>>> org1
<Organization: name>
>>> org1.active
True
>>> org2 = Organization(name='org2',active=True)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<myprojectpath>/venv/lib/python2.7/site-packages/django/db/models/base.py", line 367, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])
TypeError: 'active' is an invalid keyword argument for this function
>>>
</code></pre>