在不丢弃表格的情况下更改模型中的Django数据类型 [英] Changing the Django data type in models without dropping the table

查看:132
本文介绍了在不丢弃表格的情况下更改模型中的Django数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Django应用程序。现在我想在模型中更改我的db字段的1的字段类型。由于在数据库中已经存在一些已有的类型的记录,所以我猜想通过在models.py中改变它是不可能改变类型的。通过谷歌搜索,我知道它可以通过更改它通过sql控制台,而不会丢弃表。但是作为一个Django新手,我无法做到这一点。有人可以帮我做这个吗这是我的models.py

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆