Hey guys I'm getting an error with migrations from past two days.I added a new field into a model and then I tried to run makemigratons
It worked fine but when I tried to migrate
then I got a datetime error.After much effort i had to finally delete my database.And than It worked fine but when I try to migrate It now shows me
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: app_upload
Even though I have a Upload model
here,s the models.py
from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
from tinymce import HTMLField
from datetime import datetime
class Category(models.Model):
title = models.CharField(max_length = 20)
def __str__(self):
return self.title
class Post(models.Model):
image = models.ImageField()
title = models.CharField(max_length = 100)
body = HTMLField()
published_date = models.DateTimeField(auto_now_add = True)
categories = models.ManyToManyField(Category)
featured = models.BooleanField(default = False)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('blog',kwargs = {
'pk':self.pk
})
@property
def get_comments(self):
return self.comments.all()
class Comment(models.Model):
post = models.ForeignKey(Post,on_delete=models.CASCADE,related_name = "comments")
name = models.CharField(max_length = 200)
body = models.TextField(default = True)
parent = models.ForeignKey("self",on_delete = models.CASCADE)
pub_date = models.DateTimeField(auto_now_add = True)
class Meta:
ordering = ['-pub_date']
def __str__(self):
return self.name
def children(self):
return Comment.objects.filter(parent = self)
@property
def is_parent(self):
if self.parent is not None:
return False
return True
class Upload(models.Model):
image = models.ImageField(upload_to = 'images',)
file = models.FileField(upload_to = 'images/%Y/%M/%d/')
Here,s the migration that was created
# Generated by Django 2.1.7 on 2019-02-27 13:37
from django.db import migrations, models
import django.db.models.deletion
import tinymce.models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=20)),
],
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('body', models.TextField(default=True)),
('pub_date', models.DateTimeField(auto_now_add=True)),
('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.Comment')),
],
options={
'ordering': ['-pub_date'],
},
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.ImageField(upload_to='')),
('title', models.CharField(max_length=100)),
('body', tinymce.models.HTMLField()),
('published_date', models.DateTimeField(auto_now_add=True)),
('featured', models.BooleanField(default=False)),
('categories', models.ManyToManyField(to='app.Category')),
],
),
migrations.CreateModel(
name='Upload',
fields=[
('image', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.DateTimeField(auto_now_add=True)),
],
),
migrations.AddField(
model_name='comment',
name='post',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='app.Post'),
),
]
Here,s the migration for uploads.py
Generated by Django 2.1.7 on 2019-02-28 06:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0002_auto_20190227_0541'),
]
operations = [
migrations.AddField(
model_name='upload',
name='id',
field=models.AutoField(auto_created=True, default=1, primary_key=True, serialize=False, verbose_name='ID'),
preserve_default=False,
),
]