Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Retrieving data from Oracle DB table with column name containing special character [RSS Feed]

#1 Jan. 7, 2011 01:14:33

V.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Retrieving data from Oracle DB table with column name containing special character


Hi,

I have an existing table in my Oracle db called Sess. Few columns in
this table have names that end with the character '#'. I am unable to
run the command syncdb.

Steps I did so far:
1. python manage.py inspectdb > models.py
2. Spruced up models.py to reflect only single table called Sess.
3. Running python manage.py syncdb

The step 3 fails with error:
__________________________________________
File "D:\Vikram\Software\PythonEncode\lib\site-packages\django\db
\models\loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "D:\Vikram\Software\PythonEncode\lib\site-packages\django\utils
\importlib.py", line 35, in import_module
__import__(name)
File "D:\Vikram\Personal\Python\django\database\monitor\models.py",
line 12, in <module>
class Sess(models.Model):
File "D:\Vikram\Personal\Python\django\database\monitor\models.py",
line 15, in Sess
serial# = models.DecimalField(null=True, max_digits=10,
decimal_places=2, blank=True)
NameError: name 'serial' is not defined
__________________________________________

The code is as below:
__________________________________________
from django.db import models

class Sess(models.Model):
saddr = models.TextField(blank=True) # This field type is a guess.
sid = models.DecimalField(null=True, max_digits=10,
decimal_places=2, blank=True)
serial# = models.DecimalField(null=True, max_digits=10,
decimal_places=2, blank=True)
audsid = models.DecimalField(null=True, max_digits=10,
decimal_places=2, blank=True)
paddr = models.TextField(blank=True) # This field type is a guess.
user# = models.DecimalField(null=True, max_digits=10,
decimal_places=2, blank=True)
__________________________________________

Please advise how the '#' has to be interpreted here.

Thanks in advance,
Vikram

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 7, 2011 01:55:37

I.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Retrieving data from Oracle DB table with column name containing special character


On Jan 6, 6:14 pm, Vikram <vikramsingh...@gmail.com> wrote:
> Hi,
>
> I have an existing table in my Oracle db called Sess. Few columns in
> this table have names that end with the character '#'. I am unable to
> run the command syncdb.
>
> Steps I did so far:
> 1. python manage.py inspectdb > models.py
> 2. Spruced up models.py to reflect only single table called Sess.
> 3. Running python manage.py syncdb

syncdb is only used to create tables. If the table already exists,
then there is no reason to run it.

>   File "D:\Vikram\Personal\Python\django\database\monitor\models.py",
> line 15, in Sess
>     serial# = models.DecimalField(null=True, max_digits=10,
> decimal_places=2, blank=True)
> NameError: name 'serial' is not defined

The '#' symbol is not allowed in Python identifiers. Python
interprets the statement above as being just the identifier 'serial',
and the rest of the line is interpreted as a comment.

You need to name the field as something that does not include the '#'
symbol and use the 'db_column' option to tell Django that the name of
the column in the database is different. For example:

serial = models.DecimalField(null=True, max_digits=10,
decimal_places=2, blank=True, db_column='serial#')

Cheers,
Ian

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Retrieving data from Oracle DB table with column name containing special character [RSS Feed]

Board footer

Moderator control

Enjoy the 21st of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support