2012-12-17 3 views
7

Django 1.5(1,5,0、 'beta'、2)の新しいConfigurable user modelを使用すると、私は私のユーザモデル、ワークフローのために必要な値でfixtures/initial_data.yamlをしましたのでDjango 1.5の設定可能なユーザモデルに必要な外部キーです、createsuperuser:AttributeError: 'NoneType'オブジェクトに '_state'属性がありません

AttributeError: 'NoneType' object has no attribute '_state'

です:

  1. 作成必須フィールドの外部キーを設定しようとmanage.py createsuperuserを実行している間、私はこのエラーを取得しますデータベース
  2. python manage.py syncdb
  3. 質問に「no」と答えるあなたはスーパーユーザが定義されていないという意味でDjangoの認証システムをインストールしたばかりです。今すぐ作成しますか? (はい/いいえ)
  4. インストール14264オブジェクトない(S)1つの固定具(S)
  5. パイソンmanage.py createsuperuser

からIは、器具がインポートされた後、スーパーユーザーを作成しようとするので、これはCityモデルの空のデータベーステーブルによって引き起こされる問題ではありません。

documentationに基づいてコードの抜粋、:

class City(models.Model): 
    city = models.CharField(max_length=70, help_text="City.") 
    state = models.CharField(max_length=2, help_text="State.") 
    class Meta: 
     ordering = ['city'] 
    def __unicode__(self): 
     return "%s (%s)" % (self.city, self.state) 

class PersonaManager(BaseUserManager): 
    [...] 
    def create_superuser(self, email, name, birthplace, password): 
     """ 
     Creates and saves a superuser with the given email, date of 
     birth and password. 
     """ 
     user = self.create_user(email, 
      password=password, 
      name=name, 
      birthplace=birthplace, 
     ) 
     user.is_admin = True 
     user.save(using=self._db) 
     return user 

class Person(AbstractBaseUser): 
    email = models.EmailField(
     verbose_name='email address', 
     max_length=255, 
     unique=True, 
     db_index=True, 
    ) 
    name = models.CharField(max_length=60) 
    birthplace = models.ForeignKey('myapp.City', related_name="person_birthplace") 
    is_active = models.BooleanField(default=True) 
    is_admin = models.BooleanField(default=False) 

    objects = PersonaManager() 

    USERNAME_FIELD = 'email' 
    REQUIRED_FIELDS = ['name', 'birthplace'] 

models.pyにはどうすれば必須フィールド上の私のユーザモデルに取り組んで外部キーを入手できますか?ありがとうございました。

編集:manage.py createsuperuser --tracebackから トレースバック:これはそれを修正することを確認し、ちょうど蹴りのための

Traceback (most recent call last): 
    File "/home/asd/Envs/envdjango15/local/lib/python2.7/site-packages/django/core/management/base.py", line 222, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "/home/asd/Envs/envdjango15/local/lib/python2.7/site-packages/django/core/management/base.py", line 252, in execute 
    output = self.handle(*args, **options) 
    File "/home/asd/Envs/envdjango15/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 112, in handle 
    user_data[field_name] = field.clean(raw_value, None) 
    File "/home/asd/Envs/envdjango15/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 211, in clean 
    self.validate(value, model_instance) 
    File "/home/asd/Envs/envdjango15/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1014, in validate 
    using = router.db_for_read(model_instance.__class__, instance=model_instance) 
    File "/home/asd/Envs/envdjango15/local/lib/python2.7/site-packages/django/db/utils.py", line 142, in _route_db 
    return hints['instance']._state.db or DEFAULT_DB_ALIAS 
AttributeError: 'NoneType' object has no attribute '_state' 
AttributeError: 'NoneType' object has no attribute '_state' 
+1

完全なスタックトレースはどこにありますか? – borges

+0

私はトレースバックオプション付きのcreatesuperuserを実行しました:上記の結果を含めました。 – chirale

+1

あなたのプロジェクトで複数のデータベースを使用していますか? – OrPo

答えて

3

ない100%、PermissionsMixinにタックし、モデルオフIS_SUPERUSERをオフにヤンク。

おそらく、何らかの種類の権限チェックがバックグラウンドで行われている可能性があります。それは起こってはいけないが、ショットを付けてください。

私の疑念は、それが適用する必要があるどのモデル許可を盗聴しようとしているのかという概念から来ています。

関連する問題