First, I was able to fix the ImportError. I figured out that it was because the Django version of pythonanywhere is not updated, So I upgraded Django on pythonanywhere from 1.x.x to 2.0.9.
The error came out like this:
ImportError at / cannot import name 'path'
django version: 1.x.x
python version: 3.6.6
and, unfortunately, my app gave me another error:
OperationalError at / no such column: blog_post.published_date Request Method: GET Request URL: http://.pythonanywhere.com/ Django Version: 2.0.9 Exception Type: OperationalError Exception Value:
no such column: blog_post.published_date Exception Location: /home//my-first-blog/myenv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py in execute, line 303 Python Executable: /usr/local/bin/uwsgi Python Version: 3.6.6
I thought this error occurred because of some database, so I tried migrate
or makemigrations
on pythonanywhere, but I could not fix it still.
So, is there anyone who knows how to fix this database?
Here is my model.py
:
from django.conf import settings
from django.db import models
from django.utils import timezone
class Post(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
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
here is the output of python manage.py showmigrations
:
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
blog
[X] 0001_initial
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial