Discussion:
about django model save
(too old to reply)
chen gang
2009-12-25 02:02:05 UTC
Permalink
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
[***@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

--

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(夏恺)
2009-12-25 02:17:19 UTC
Permalink
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(夏恺)
***@gmail.com
http://blog.xiaket.org

--------------------------------------------------
From: "chen gang" <***@nokia.com>
Sent: Friday, December 25, 2009 10:02 AM
To: <django-***@googlegroups.com>
Subject: about django model save
Post by chen gang
Hi,
I am really new to this tool... and need you help about this issue,
thanks in advance!
I create models.py like this,
...
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
--

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.
chen gang
2009-12-25 02:33:11 UTC
Permalink
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
Post by Xia Kai(夏恺)
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
-----------------------------------------------------------------------
[^_^:~/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(夏恺)
http://blog.xiaket.org
--------------------------------------------------
Sent: Friday, December 25, 2009 10:02 AM
Subject: about django model save
Post by chen gang
Hi,
I am really new to this tool... and need you help about this issue,
thanks in advance!
I create models.py like this,
...
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
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--

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(夏恺)
2009-12-25 02:53:32 UTC
Permalink
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(夏恺)
***@gmail.com
http://blog.xiaket.org

--------------------------------------------------
From: "chen gang" <***@nokia.com>
Sent: Friday, December 25, 2009 10:02 AM
To: <django-***@googlegroups.com>
Subject: about django model save
Post by chen gang
Hi,
I am really new to this tool... and need you help about this issue,
thanks in advance!
I create models.py like this,
...
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
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;
--

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.
chen gang
2009-12-25 05:09:46 UTC
Permalink
Hi,

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


Br, Chen Gang
Post by Xia Kai(夏恺)
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(夏恺)
http://blog.xiaket.org
--------------------------------------------------
Sent: Friday, December 25, 2009 10:02 AM
Subject: about django model save
Post by chen gang
Hi,
I am really new to this tool... and need you help about this issue,
thanks in advance!
I create models.py like this,
...
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
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;
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--

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.
Victor Lima
2009-12-25 15:40:00 UTC
Permalink
Try deleting the table and then syncdb again...

Att,
Victor Lima
Post by chen gang
Hi,
I am really new to this tool... and need you help about this issue,
thanks in advance!
I create models.py like this,
...
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
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()
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
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
.
--

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.
Carlos Ricardo Santos
2009-12-25 15:43:05 UTC
Permalink
You may want to try django-evolution.
It "clones" the rake migrations of Rails :D
Not so good... but if fits.
Post by Victor Lima
Try deleting the table and then syncdb again...
Att,
Victor Lima
Post by chen gang
Hi,
I am really new to this tool... and need you help about this issue,
thanks in advance!
I create models.py like this,
...
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
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()
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
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
Post by chen gang
.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
Cumprimentos,
Carlos Ricardo Santos

--

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.
Shawn Milochik
2009-12-25 18:05:43 UTC
Permalink
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.
Carlos Ricardo Santos
2009-12-26 14:29:27 UTC
Permalink
Thanks for remind me about South.
This really looks amazing!
No more "rm db && manage.py syncdb"
:D
Post by Shawn Milochik
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 unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
Cumprimentos,
Carlos Ricardo Santos

--

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.
Continue reading on narkive:
Loading...