I was trying to alter some column fields in my MySQL table by modifying the class "test" below and messed it up in a bad way, I also deleted the migration files.
I am new to models and migrations but I am trying to understand on how to modify a table or columns in a proper way.
1) I have seen people modify the test class directly, for example if I would like to change the decimal_places to 5 instead of 4 they just changed the number and ran makemigrations. This is how I did it, sometimes it worked and sometimes it didn't recognize any changes. And now the last time it messed up my unique_together() function.
After some research it seems that I should create a table with class test(models.Model) and then from there on If I would like to change something I should use the ALTER TABLE function?
2) Since I now have ruined a well functioning database I would like to delete my table and create a new models.py and do the setup all over again. Is this a "proper" way of doing it or is there something smoother than just DROP TABLE and deleting the models.py and migrations?
# Create your models here.
class test(models.Model):
birth = models.DateTimeField(blank=True, null=True)
published = models.CharField(primary_key=True, max_length=50)
city = models.CharField(max_length=50)
price = models.DecimalField(max_digits=10, decimal_places=4, null=True)
something = models.CharField(max_length=5, blank=True, null=True)
class Meta:
managed = True
db_table = 'test'
unique_together = (('published', 'city', 'price'),)
def __str__(self):
return self.names