Django:auth:emailにUNIQUEインデックスを張る

>>> u=User.objects.create_user(‘x’,’x@hdknr.test’,’x’)
>>> u=User.objects.create_user(‘x’,’y@hdknr.test’,’x’)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/var/lib/python-support/python2.5/django/contrib/auth/models.py", line 114, in create_user
    user.save()
  File "/var/lib/python-support/python2.5/django/db/models/base.py", line 311, in save
    self.save_base(force_insert=force_insert, force_update=force_update)
  File "/var/lib/python-support/python2.5/django/db/models/base.py", line 383, in save_base
    result = manager._insert(values, return_id=update_pk)
  File "/var/lib/python-support/python2.5/django/db/models/manager.py", line 138, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/var/lib/python-support/python2.5/django/db/models/query.py", line 894, in insert_query
    return query.execute_sql(return_id)
  File "/var/lib/python-support/python2.5/django/db/models/sql/subqueries.py", line 309, in execute_sql
    cursor = super(InsertQuery, self).execute_sql(None)
  File "/var/lib/python-support/python2.5/django/db/models/sql/query.py", line 1734, in execute_sql
    cursor.execute(sql, params)
  File "/var/lib/python-support/python2.5/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
  File "/var/lib/python-support/python2.5/django/db/backends/mysql/base.py", line 83, in execute
    return self.cursor.execute(query, args)
  File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
IntegrityError: (1062, "Duplicate entry ‘x’ for key 2")

deb09:~# echo "alter table auth_user add unique EM (email)" | mysql tohyo

>>> u=User.objects.create_user(‘y’,’x@hdknr.test’,’x’)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/var/lib/python-support/python2.5/django/contrib/auth/models.py", line 114, in create_user
    user.save()
  File "/var/lib/python-support/python2.5/django/db/models/base.py", line 311, in save
    self.save_base(force_insert=force_insert, force_update=force_update)
  File "/var/lib/python-support/python2.5/django/db/models/base.py", line 383, in save_base
    result = manager._insert(values, return_id=update_pk)
  File "/var/lib/python-support/python2.5/django/db/models/manager.py", line 138, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/var/lib/python-support/python2.5/django/db/models/query.py", line 894, in insert_query
    return query.execute_sql(return_id)
  File "/var/lib/python-support/python2.5/django/db/models/sql/subqueries.py", line 309, in execute_sql
    cursor = super(InsertQuery, self).execute_sql(None)
  File "/var/lib/python-support/python2.5/django/db/models/sql/query.py", line 1734, in execute_sql
    cursor.execute(sql, params)
  File "/var/lib/python-support/python2.5/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
  File "/var/lib/python-support/python2.5/django/db/backends/mysql/base.py", line 83, in execute
    return self.cursor.execute(query, args)
  File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
IntegrityError: (1062, "Duplicate entry ‘x@hdknr.test’ for key 3")

カテゴリー: 未分類 パーマリンク

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中