私はUser
djangoを拡張していますが、電話番号を追加する必要があることに気づきませんでした。makemigrations
migrate
以下のモデルを作成したとき、AppUser を作成する前に忘れていました。そのため、通常どおり AppUser/User コンボを作成しましたが、データベースの準備が整う前でした。デフォルトを指定するように求められますが、整数として 1 を使用できないため、文字列 '1' を指定しました
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import RegexValidator
class AppUser(models.Model):
user = models.OneToOneField(User, primary_key=True, on_delete=models.CASCADE)
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
phone_number = models.CharField(validators=[phone_regex], max_length=16, blank=True) # validators should be a list
def __str__(self):
return self.first_name + " " + self.last_name + ": " + self.email
今、私は触れることができませんUser
またはAppUser
:
In [4]: appusers = AppUser.objects.all()
In [5]: for user in appusers:
...: user.delete()
...:
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/backends/utils.py in execute(self, sql, params)
63 else:
---> 64 return self.cursor.execute(sql, params)
65
ProgrammingError: column users_appuser.id does not exist
LINE 1: SELECT "users_appuser"."id", "users_appuser"."user_id", "use...
^
The above exception was the direct cause of the following exception:
ProgrammingError Traceback (most recent call last)
<ipython-input-5-fd4a00b110e0> in <module>()
----> 1 for user in appusers:
2 user.delete()
3
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/models/query.py in __iter__(self)
254 - Responsible for turning the rows into model objects.
255 """
--> 256 self._fetch_all()
257 return iter(self._result_cache)
258
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/models/query.py in _fetch_all(self)
1085 def _fetch_all(self):
1086 if self._result_cache is None:
-> 1087 self._result_cache = list(self.iterator())
1088 if self._prefetch_related_lookups and not self._prefetch_done:
1089 self._prefetch_related_objects()
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/models/query.py in __iter__(self)
52 # Execute the query. This will also fill compiler.select, klass_info,
53 # and annotations.
---> 54 results = compiler.execute_sql()
55 select, klass_info, annotation_col_map = (compiler.select, compiler.klass_info,
56 compiler.annotation_col_map)
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/models/sql/compiler.py in execute_sql(self, result_type)
833 cursor = self.connection.cursor()
834 try:
--> 835 cursor.execute(sql, params)
836 except Exception:
837 cursor.close()
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/backends/utils.py in execute(self, sql, params)
77 start = time()
78 try:
---> 79 return super(CursorDebugWrapper, self).execute(sql, params)
80 finally:
81 stop = time()
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/backends/utils.py in execute(self, sql, params)
62 return self.cursor.execute(sql)
63 else:
---> 64 return self.cursor.execute(sql, params)
65
66 def executemany(self, sql, param_list):
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/utils.py in __exit__(self, exc_type, exc_value, traceback)
92 if dj_exc_type not in (DataError, IntegrityError):
93 self.wrapper.errors_occurred = True
---> 94 six.reraise(dj_exc_type, dj_exc_value, traceback)
95
96 def __call__(self, func):
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/utils/six.py in reraise(tp, value, tb)
683 value = tp()
684 if value.__traceback__ is not tb:
--> 685 raise value.with_traceback(tb)
686 raise value
687
/home/cchilders/.virtualenvs/austin_eats/lib/python3.5/site-packages/django/db/backends/utils.py in execute(self, sql, params)
62 return self.cursor.execute(sql)
63 else:
---> 64 return self.cursor.execute(sql, params)
65
66 def executemany(self, sql, param_list):
ProgrammingError: column users_appuser.id does not exist
LINE 1: SELECT "users_appuser"."id", "users_appuser"."user_id", "use...
他の場合も同じ:
In [3]: for user in users:
...: user.delete()
blah blah
ProgrammingError: column users_appuser.user_id does not exist
LINE 1: DELETE FROM "users_appuser" WHERE "users_appuser"."user_id" ...
データベース全体を削除して再作成せずに、この汚物を修復できますか? ありがとうございました