views:

29

answers:

2

I just migrated my django application from sqlite3 to mysql 5.1.41. I have a charfield in a model defined like this:

class HostData(models.Model):
  Host = models.CharField(max_length=50, null=True)
  HostStatus = models.CharField(max_length=200, null=True)
  Alarm = models.BooleanField()

Everything works the same except HostStatus, which usually returns a string like "Up, waiting". In mysql, however, it is blank. I created my table with character set to utf-8. What am I doing wrong? Thanks in advance.

+1  A: 

I can't see anything wrong with that model code.

How have you migrated your data over to MySQL? When you enter data via the django admin, does it enter data into the db?

If a view is entering this data, can you post the view code.

Stuart Marsh
Thanks for your input Stuart. I found the issue which is described in my answer.
Ping Pengũin
A: 

The issue was the way I was assigning the value to the model. I dont know why it worked well in sqlite, but it was bad coding anyways. This is what I was doing:

myarray = stdout_ssh
myobject = test.object.get(id=3)
myobject.Host = stdout_ssh[0]
myobject.HostStatus = status
status = stdout_ssh[1]
myobject.Alarm = False
myobject.save()

I changed this to:

myarray = stdout_ssh
myobject = test.object.get(id=3)
myobject.Host = stdout_ssh[0]
myobject.HostStatus = stdout_ssh[1]
myobject.Alarm = False
myobject.save()

And everything was ok.

Ping Pengũin