我将Django数据库模型迁移到MySQL。当我尝试在MySQL中访问数据时,似乎找不到现有数据。我该如何解决?
迁移代码:
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sample',
'USER': '********',
"PASSWORD": '********',
'HOST': '*****',
'PORT': '*****',
'OPTIONS': {
'sql_mode': 'traditional',
}
}
}
models.py
from django.db import models
import os
from PIL import Image
from datetime import date
import datetime
from .validators import validate_file_extension
import base64
from django.utils.functional import cached_property
from django.utils.html import format_html
def get_directory_path(instance, filename):
today = date.today()
t = datetime.datetime.now()
day, month, year = today.day, today.month, today.year
hour, minutes, seconds = t.hour, t.minute, t.second
filename = str(day) + str(month) + str(year) + str(hour) + str(minutes) + str(seconds) + '.png'
dir = 'media'
path = '{0}/{1}'.format(dir, filename)
return path
class Image(models.Model):
image = models.FileField(upload_to = get_directory_path, null = True , validators=[validate_file_extension])
created_date = models.DateTimeField(auto_now = True)
def __str__(self):
return str(self.id)
此后,我输入:
python manage.py makemigrations
python manage.py migrate
一切似乎都正常,但是我无法查看我的数据。有什么建议吗?
答案 0 :(得分:0)
您以前使用过sqlite吗?更改数据库并迁移后,在MySql中仅创建数据库架构(表)。您将丢失以前的所有数据,并且无法检索它们。