0

Okay so I have a problem where I designed a model in django and now I need to delete the table in my DB that my model is associated with. I looked around and could not find any suitable instructions for how to do this django 1.9 so I thought I would ask here.

Basically, I have a model-form like this:

class Query(models.Model):
  studyName = models.CharField(max_length=250)
  population = models.IntegerField()
  intervention = models.CharField(max_length=250)
  comparison = models.CharField(max_length=250)
  outcome = models.CharField(max_length=250)
  outcomeTiming = models.CharField(max_length=250)
  processed_data = models.CharField(max_length=10000)

  updated = models.DateTimeField(auto_now=True, auto_now_add=False)
  timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)

and I want to change it to be:

class Query(models.Model):
  Study_Design = models.TextField()
  Study_Data = models.TextField()
  Study_Tools = models.TextField()
  processed_data = models.TextField()

  updated = models.DateTimeField(auto_now=True, auto_now_add=False)
  timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)

Any help is appreciated.

jdv12
  • 171
  • 4
  • 17
  • Then change it. What's stopping you? Any errors? – v1k45 Apr 05 '16 at 16:47
  • 1
    Are you using migrations? If so, then you should just be able to run `manage.py makemigrations` and then `manage.py migrate`. – Rob Vezina Apr 05 '16 at 16:47
  • When I make the changes and run makemigrations I get this message. You are trying to add a non-nullable field 'Study_Data' to query 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) 2) Quit, and let me add a default in models.py Select an option: – jdv12 Apr 05 '16 at 16:57
  • It looks like you are making a pretty drastic change to your model and don't really care about any existing data. With that in mind, choose option 1 and enter any value you want for the default. I usually just enter '1' as the one-off default. – Rob Vezina Apr 05 '16 at 17:15
  • Ah I solved it. I just needed to add a default parameter in my form call. – jdv12 Apr 05 '16 at 17:16
  • That works too. That's option 2 of the message you were presented with. Glad you got it working. – Rob Vezina Apr 05 '16 at 17:18

0 Answers0