서버에 로컬 작업을 배포하려고하는데 python manage.py에서 migrate를 실행할 때 psycopg2에 문제가 있습니다.마이그레이션 할 때 오류가 발생했습니다 - psycopg2 Django
설정 :
DATABASES = {
'default':{
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '******',
'USER': '*****',
'PASSWORD': '**********',
'HOST': '*******',
'PORT': '5432'
}
}
모델은 문제를 가졌
class user(AbstractBaseUser, PermissionsMixin):
created = models.DateTimeField(auto_now_add=True)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField(unique=True)
street = models.CharField(max_length=100, null=True, blank=True)
street_num = models.CharField(max_length=10, null=True, blank=True)
unit_num = models.CharField(max_length=10, null=True, blank=True)
city = models.CharField(max_length=50, null=True, blank=True)
postal_code = models.CharField(max_length=10, null=True, blank=True)
state = models.ForeignKey(state, null=True, blank=True)
country = models.ForeignKey(country, null=True, blank=True)
phone = models.CharField(max_length=50, null=True, blank=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
.....
class country(models.Model):
name = models.CharField(max_length=50)
code = models.CharField(max_length=10)
class State(models.Model):
country = models.ForeignKey(country, on_delete=models.CASCADE)
name = models.CharField(max_length=50)
short_name = models.CharField(max_length=3)
group = models.CharField(max_length=2, null=True, blank=True, choices=GROUP_TYPE)
properties = models.ForeignKey(stateProperties, null=True, blank=True)
마이그레이션 파일 : ...
('brand', models.CharField(blank=True, max_length=30, null=True)),
('exp_month', models.CharField(blank=True, max_length=2, null=True)),
('exp_year', models.CharField(blank=True, max_length=2, null=True)),
('country', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='common.country')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('state', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='common.state')),
.....
ERROR:
Running migrations:
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying profile.0001_initial...Traceback (most recent call last):
File "/home/instantuser/app/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "common_country" does not exist
**django.db.utils.ProgrammingError: relation "common_country" does not exist**
무엇이 여기에 있습니까?
왜 사용자 모델이 문제의 원인이라고 생각하십니까? 국가 모델을 보여줄 수 있습니까? 또한, 같은 장고 애플 리케이션에 두 모델입니까? –
@MananMehta 안녕하세요, 이로 인해 : profile.0001_initial 적용. 모든 sqlite dev 서버를 사용하여 로컬로 잘 작동합니다. 이것은 psycopg2를 사용하는 경우에만 발생합니다. 하지만 국가 모델을 추가하는 메신저 –
@AndreMendes 내가 대답에서 제안한 것을 시도 했습니까? –