2017-05-15 91 views
0

我试图运行我的Django应用与PostgreSQL作为我的数据库引擎较早使用sqlite, 这是我的settings.py。我被教程做安装https://djangogirls.gitbooks.io/django-girls-tutorial-extensions/optional_postgresql_installation/Djago错误与PostgreSQL迁移

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', 
     'NAME': 'djangogirls', 
     'USER': 'cherzik', 
     'PASSWORD': 'ADMIN', 
     'HOST': 'localhost', 
    } 
} 

这是错误,帮助请

d:\py\djangogirls>python manage.py migrate 
System check identified some issues: 

WARNINGS: 
blog.Comment.created_date: (fields.W161) Fixed default value provided. 
     HINT: It seems you set a fixed date/time/datetime value as default f 
or this field. This may not be what you want. If you want to have the current da 
te as default, use `django.utils.timezone.now` 
blog.Post.created_date: (fields.W161) Fixed default value provided. 
     HINT: It seems you set a fixed date/time/datetime value as default f 
or this field. This may not be what you want. If you want to have the current da 
te as default, use `django.utils.timezone.now` 
Traceback (most recent call last): 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\base\base.py", line 213, in ensure_connection 
    self.connect() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\base\base.py", line 189, in connect 
    self.connection = self.get_new_connection(conn_params) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\postgresql\base.py", line 176, in get_new_connection 
    connection = Database.connect(**conn_params) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\psycopg2\__init__.py", line 130, in connect 
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 
psycopg2.OperationalError 

The above exception was the direct cause of the following exception: 

Traceback (most recent call last): 
    File "manage.py", line 22, in <module> 
    execute_from_command_line(sys.argv) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\core\management\__init__.py", line 363, in execute_from_command_line 
    utility.execute() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\core\management\__init__.py", line 355, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\core\management\base.py", line 283, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\core\management\base.py", line 330, in execute 
    output = self.handle(*args, **options) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\core\management\commands\migrate.py", line 83, in handle 
    executor = MigrationExecutor(connection, self.migration_progress_callback) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\migrations\executor.py", line 20, in __init__ 
    self.loader = MigrationLoader(self.connection) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\migrations\loader.py", line 52, in __init__ 
    self.build_graph() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\migrations\loader.py", line 209, in build_graph 
    self.applied_migrations = recorder.applied_migrations() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\migrations\recorder.py", line 65, in applied_migrations 
    self.ensure_schema() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\migrations\recorder.py", line 52, in ensure_schema 
    if self.Migration._meta.db_table in self.connection.introspection.table_name 
s(self.connection.cursor()): 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\base\base.py", line 254, in cursor 
    return self._cursor() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\base\base.py", line 229, in _cursor 
    self.ensure_connection() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\base\base.py", line 213, in ensure_connection 
    self.connect() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\utils.py", line 94, in __exit__ 
    six.reraise(dj_exc_type, dj_exc_value, traceback) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\utils\six.py", line 685, in reraise 
    raise value.with_traceback(tb) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\base\base.py", line 213, in ensure_connection 
    self.connect() 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\base\base.py", line 189, in connect 
    self.connection = self.get_new_connection(conn_params) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\django\db\backends\postgresql\base.py", line 176, in get_new_connection 
    connection = Database.connect(**conn_params) 
    File "C:\Users\Кирюшик\AppData\Local\Programs\Python\Python35\lib\site-package 
s\psycopg2\__init__.py", line 130, in connect 
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 
django.db.utils.OperationalError 
+0

请张贴您的模特。 – Selcuk

+0

看来您的代码无法连接到PostgreSQL。检查是否已安装并运行PostgreSQL,并且在Django设置中正确设置了postgresql数据库,用户名和密码的名称。 –

回答

0

这是我的模型,如果我更换CREATED_DATE到timezone.now像你反正说了一个错误

from django.db import models 
from django.utils import timezone 
# Create your models here. 

class Post(models.Model): 
    author = models.ForeignKey('auth.User') 
    title = models.CharField(max_length = 200) 
    text = models.TextField() 
    created_date = models.DateTimeField(default=timezone.now()) 
    published_date = models.DateTimeField(blank = True, null=True) 

    def publish(self): 
     self.published_date = timezone.now() 
     self.save() 


    def __str__(self): 
     return self.title 

    def approved_comments(self): 
     return self.comments.filter(approved_comment = True) 

class Comment(models.Model): 
    post = models.ForeignKey('blog.Post', related_name='comments') 
    author = models.CharField(max_length=200) 
    text = models.TextField() 
    created_date = timezone.now() 
    approved_comment = models.BooleanField(default=False) 

    def approve(self): 
     self.approved_comment = True 
     self.save() 

    def __str__(self): 
     return self.text 
0

改变这样的CREATED_DATE领域,

created_date = models.DateField(default=timezone.now) 

或者

created_date = models.DateField(default=datetime.date.today) 

删除功能的paranthesis。 使用paranthesis时,只有在models.py加载时才会调用该函数。 如果我们删除了paranthesis,我们将可调用对象传递给模型,并且每次保存新实例时都会调用它。