我遇到了django的问题,我试图在我的应用程序上为django创建一个数据库我已经设置了这样的连接
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'Proyecto_OSC',
'USER': 'posgresql',
'PASSWORD': 'aa121292',
'HOST': '',
'PORT': '5432'
}
}
然后我尝试创建这样的模型:
class TipoOrganizacion(models.Model):
nombre = models.CharField(max_length=140)
def __str__(self):
return self.nombre
class Meta:
verbose_name_plural = "Tipos de Organizacion"
class Actividades(models.Model):
nombre = models.CharField(max_length=255)
def __str__(self):
return self.nombre
class Meta:
verbose_name_plural = "Actividades"
class AreasInteres(models.Model):
nombre = models.CharField(max_length=255)
def __str__(self):
return self.nombre
class Meta:
verbose_name_plural = "Areas de interes"
verbose_name = "Area de interes"
class TiposRedesSociales(models.Model):
tipo = models.CharField(max_length=255)
def __str__(self):
return self.tipo
class Meta:
verbose_name_plural = "Tipos de redes sociales"
verbose_name = "tipo de red social"
class RedSocial(models.Model):
nombre = models.CharField(max_length=255)
tipo = models.ManyToManyField(TiposRedesSociales)
def __str__(self):
return self.nombre
class Meta:
verbose_name_plural = "Redes sociales"
verbose_name = "Red social"
class Organizacion(models.Model):
nombre = models.CharField(max_length=150)
poblacion = models.CharField(max_length=100)
direccion = models.CharField(max_length=200)
fecha = models.DateField()
telefono = models.CharField(max_length=15)
dias = models.CharField(max_length=200)
iniciohora = models.TimeField()
finhora = models.TimeField()
nombrecontacto = models.CharField(max_length=150)
numeropersonas = models.CharField(max_length=3)
recursos = models.CharField(max_length=255)
tipo = models.ForeignKey(TipoOrganizacion)
actividades = models.ManyToManyField(Actividades)
areas = models.ManyToManyField(AreasInteres)
red = models.ForeignKey(RedSocial)
def __str__(self):
return self.nombre
class Meta:
verbose_name_plural = "organizaciones"
verbose_name = "organizacion"
我已经尝试过manage.py验证以验证我的模型上的语法错误,并说出0错误,然后在执行syncdb后发生这种情况:
C:\Users\Abdul Hamid\PycharmProjects\Proyecto_OSC>python manage.py syncdb
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 127, in ensure_connection
self.connect()
File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 115, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Python34\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 114, in get_new_connection
return Database.connect(**conn_params)
File "C:\Python34\lib\site-packages\psycopg2\__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 415, in handle
return self.handle_noargs(**options)
File "C:\Python34\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 160, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 132, in _cursor
self.ensure_connection()
File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 127, in ensure_connection
self.connect()
File "C:\Python34\lib\site-packages\django\db\utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 549, in reraise
raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 127, in ensure_connection
self.connect()
File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 115, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Python34\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 114, in get_new_connection
return Database.connect(**conn_params)
File "C:\Python34\lib\site-packages\psycopg2\__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError
所以我已经尝试使用pgadminIII在postgres中创建数据库而不创建表 并且它一直在破坏这个错误,我想知道我是否必须用所有表创建整个数据库,或者django是否只是编写模型来创建整个数据库? 难道我做错了什么?我相信我,但我不确定
我不是一个专业的想法 我还在学习对不起我的英语,这不是我的第一语言
顺便提前谢谢
答案 0 :(得分:0)
如果您与其他人共享文件,则他们的postgres密码很可能与您的密码不同,因此请务必正确设置“PASSWORD”:以便您使用自己的密码。