I create models.py like this,
...
class Sms_detailed(models.Model):
group = models.CharField(max_length=15)
phone_num = models.CharField(max_length=15)
IMEI = models.CharField(max_length=15)
sw_ver = models.CharField(max_length=20)
project = models.CharField(max_length=10)
sw_checksum = models.CharField(max_length=10)
recv_date_time = models.DateTimeField()
raw_data = models.CharField(max_length=30) # raw reset data
...
Then create the db
[gachen@pipi autosms]$ python manage.py sql asms
BEGIN;
....
CREATE TABLE "asms_sms_detailed" (
"id" integer NOT NULL PRIMARY KEY,
"group" varchar(15) NOT NULL,
"phone_num" varchar(15) NOT NULL,
"IMEI" varchar(15) NOT NULL,
"sw_ver" varchar(20) NOT NULL,
"project" varchar(10) NOT NULL,
"sw_checksum" varchar(10) NOT NULL,
"recv_date_time" datetime NOT NULL,
"raw_data" varchar(30) NOT NULL
)
;
...
COMMIT;
but when I am trying to save a object,
sms_detailed = Sms_detailed(group='test',phone_num =
'123456',IMEI='1234',sw_ver='3.03',sw_checksum='1234',project='rh-125',recv_date_time=datetime.datetime.now(),raw_data='s1234')
>>> sms_detailed.save()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line
410, in save
self.save_base(force_insert=force_insert, force_update=force_update)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line
495, in save_base
result = manager._insert(values, return_id=update_pk)
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
line 177, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 1087, in insert_query
return query.execute_sql(return_id)
File
"/usr/lib/python2.6/site-packages/django/db/models/sql/subqueries.py",
line 320, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py",
line 2369, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py",
line 19, in execute
return self.cursor.execute(sql, params)
File
"/usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py",
line 193, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: table asms_sms_detailed has no column named phone_num
Br, Chen Gang
It seemed that your db is not created, try to use
python manage.py syncdb
to create the database.
manage.py sql would only print the statements which would be used to created
the database:
-----------------------------------------------------------------------
[^_^:~/msgcenter-django/msgcenter]python manage.py help sql
Usage: manage.py sql [options] <appname appname ...>
Prints the CREATE TABLE SQL statements for the given app name(s).
-----------------------------------------------------------------------
------------------------
Xia Kai(夏恺)
xia...@gmail.com
http://blog.xiaket.org
--------------------------------------------------
From: "chen gang" <gang...@nokia.com>
Sent: Friday, December 25, 2009 10:02 AM
To: <django...@googlegroups.com>
Subject: about django model save
thanks for the quick reply.
Actually I call "python manage.py syncdb " and I just didn't mention it
in previous mail. I can save other type of models defined in my
models.py. Is this a bug (my poor guess)?
Br. Chen Gang
> --
>
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>
It seemed that you have run syncdb before your adding the phone_num to the
model.
As the table is already created in the database, you may have to delete the
table and create it again.
------------------------
Xia Kai(夏恺)
xia...@gmail.com
http://blog.xiaket.org
--------------------------------------------------
From: "chen gang" <gang...@nokia.com>
Sent: Friday, December 25, 2009 10:02 AM
To: <django...@googlegroups.com>
Subject: about django model save
> Hi,
after some discussion with XIa Kai and I tried to delete the .db file
and rebuild it. it works now!
Br, Chen Gang
Att,
Victor Lima
Shawn
Django-south is the best solution right now. Django-evolution is no longer developed, as the author thinks South is the current best solution.
http://south.aeracode.org/
Shawn
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.