2

I have two model classes they like below:


from django.db import models
from django.urls import reverse

class Place(models.Model):
    address = models.CharField(max_length=80)


class Author(Place):
    name = models.CharField(max_length=50)

But when i want to execute makemigartions django shows me error below:

You are trying to add a non-nullable field 'place_ptr' to author without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py
Select an option: 

I have some data in Author table but i dont want to remove that data.

is there anyone could help me please ?

1 Answers1

1

You can delete the old migrations file or entire migration folder for the specific app and then do the python manage.py makemigrations <app_name>
If this is not the solution you wanted then you can find the solution here.

dipesh
  • 763
  • 2
  • 9
  • 27
  • it does all migration process but there seems to be a problem place table is not generated in my database. in migrate log it shows: book/migrations/0001_initial.py - Create model Place - Create model Author – DeepRockWeb Aug 05 '19 at 08:50
  • in database table name will be in the form of ```_```. Do you look at that? – dipesh Aug 05 '19 at 08:54
  • 1
    no i didnt find that. aslo i try to fetch Place data model from database by executing Place.objects.all() but it shows me django.db.utils.OperationalError: no such table: book_place – DeepRockWeb Aug 05 '19 at 09:10