Sunday, May 31, 2015

Problem in updating database models.

I am using Django 1.8 to build a demo project.Inside my project I have one app 'Book'.Book app initially had this model - 

class Book(models.Model):
      title = models.CharField(max_length=200)
      author = models.TextField()
      pub_date = models.DateTimeField('date published')

I applied makemigrations and then filled some data through my frontend website.Now Book model has 3 rows. Now I wanted to add another field to Book model like this  -

class Book(models.Model):
      title = models.CharField(max_length=200)
      author = models.TextField()
      pub_date = models.DateTimeField('date published')
       thumbnail
= models.FileField(upload_to=get_upload_file_name)

In fear of losing my existing data I dumped my data in a json file using python manage.py dumpdata command. Now what are the next steps in this?I mean now I want to empty the whole book table.Then apply makemigrations because I added one field.Also will I have to add default to thumbnail field when applying migrations?
After that I want to populate the table again from an existing json file.

Thanks.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c7e8b057-3aed-43f9-815e-3b225da6705f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment