在不丢弃表格的情况下更改模型中的Django数据类型 [英] Changing the Django data type in models without dropping the table
问题描述
class EmployeeDetails(models.Model):
userName = models.CharField(max_length = 200)
名称= models.CharField(max_length = 200)
employeeID = models.IntegerField()
contactNumber = models.CharField(max_length = 200)
project = models.CharField (max_length = 200)
dateOfJoin = models.TextField()
现在我想改变dateOfJoin = models.DateField()。我如何通过使用sql控制台命令将TextFieild更改为DateField?
我以其他方式工作。我通过sql控制台选择了我的数据库,并用sql查询添加了新的列。那工作很好:),非常感谢你们给你的帮助。
I have created a Django application. Now i wanted to change the field type for 1 of my db field in models. Since there are some records already in the database with the present type, i guess its not possible to change the type by simply changing it in models.py. By googling i came to know that it can be changed without dropping the tables by changing it through sql console. But being a Django newbie i am not able to do this. Can somebody help me to do this? This is my models.py
class EmployeeDetails(models.Model):
userName = models.CharField(max_length=200)
designation = models.CharField(max_length=200)
employeeID = models.IntegerField()
contactNumber = models.CharField(max_length=200)
project = models.CharField(max_length=200)
dateOfJoin=models.TextField()
Now i want to change the dateOfJoin = models.DateField(). How can i change the TextFieild to DateField without droping the table by using sql console commands?
I got it working in another way. I selected my database through sql console and added new columns with sql query. And that worked just fine :), Thanks a lot for the help u guys gave..
这篇关于在不丢弃表格的情况下更改模型中的Django数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!