about django model save

8 views
Skip to first unread message

chen gang

unread,
Dec 24, 2009, 9:02:05 PM12/24/09
to django...@googlegroups.com
Hi,
I am really new to this tool... and need you help about this issue,
thanks in advance!

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

Xia Kai(夏恺)

unread,
Dec 24, 2009, 9:17:19 PM12/24/09
to django...@googlegroups.com
Hi,

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

chen gang

unread,
Dec 24, 2009, 9:33:11 PM12/24/09
to django...@googlegroups.com
Hi,

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.
>
>

Xia Kai(夏恺)

unread,
Dec 24, 2009, 9:53:32 PM12/24/09
to django...@googlegroups.com
Hi,

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,

chen gang

unread,
Dec 25, 2009, 12:09:46 AM12/25/09
to django...@googlegroups.com
Hi,

after some discussion with XIa Kai and I tried to delete the .db file
and rebuild it. it works now!


Br, Chen Gang

Victor Lima

unread,
Dec 25, 2009, 10:40:00 AM12/25/09
to django...@googlegroups.com, django...@googlegroups.com
Try deleting the table and then syncdb again...

Att,
Victor Lima

Carlos Ricardo Santos

unread,
Dec 25, 2009, 10:43:05 AM12/25/09
to django...@googlegroups.com
You may want to try django-evolution.
It "clones" the rake migrations of Rails :D
Not so good... but if fits.

2009/12/25 Victor Lima <victorlou...@gmail.com>



--
Cumprimentos,
Carlos Ricardo Santos

Shawn Milochik

unread,
Dec 25, 2009, 1:05:43 PM12/25/09
to django...@googlegroups.com
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

Carlos Ricardo Santos

unread,
Dec 26, 2009, 9:29:27 AM12/26/09
to django...@googlegroups.com
Thanks for remind me about South.
This really looks amazing!
No more "rm db && manage.py syncdb"
:D

2009/12/25 Shawn Milochik <sh...@milochik.com>
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.


Reply all
Reply to author
Forward
0 new messages