2017-05-15 6 views
0

Ich habe versucht, meine Django App mit PostgreSQL als meine Datenbank-Engine früher sqlite, Dies ist meine settings.py. Ich tat die Installation von Tutorial https://djangogirls.gitbooks.io/django-girls-tutorial-extensions/optional_postgresql_installation/Djago Fehler mit PostgreSQL Migration

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

dies Fehler, bitte helfen

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

Poste bitte deine Modelle. – Selcuk

+0

Es scheint, dass Ihr Code keine Verbindung zu PostgreSQL herstellen kann. Vergewissern Sie sich, dass PostgreSQL installiert ist und ausgeführt wird und dass der Name der postgresql-Datenbank, des Benutzers und des Passworts in den Django-Einstellungen korrekt eingestellt ist. –

Antwort

0

dies mein Modell ist, und wenn ich created_date ersetzen timezone.now wie Sie gesagt haben ohnehin einen Fehler

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

ändern der created_date Feld wie folgt,

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

Oder

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

die geklam- mert der Funktion entfernen. Mit der Paranthese wird die Funktion nur aufgerufen, wenn models.py geladen wird. Wenn wir die Paranthesis entfernen, übergeben wir eine Callable an das Modell und es wird jedes Mal aufgerufen, wenn eine neue Instanz gespeichert wird.