no such column: jobs_job.mainloc

12 views
Skip to first unread message

alex3627

unread,
Apr 13, 2012, 1:19:07 PM4/13/12
to django...@googlegroups.com
Hi all,

I am new to django and just learning, but for the current error I have absolutely no idea about the cause. I have created a model named Job in model.py which contains several elements. One of the is defined as follows:

    mainloc  = models.CharField(max_length=1, choices = MAINLOC)

and MAINLOC is a list of 2-tuples, with the first element a 1-character expression (like 'B', 'M'...). I have updated the database (the name mainloc is explicitly mentioned in the screen output), I have sync'd the database and restarted the server. But still, when I want to display the (empty) list on my browser, I get the message

   no such column: jobs_job.mainloc


Any idea or advice I could try to do?

Thanks
   Alex

Timothy Makobu

unread,
Apr 13, 2012, 1:45:22 PM4/13/12
to django...@googlegroups.com
Did you run a syncdb, then added mainloc after? Also, using south makes things much easier.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/4G24v1A5LaUJ.
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.

alex3627

unread,
Apr 13, 2012, 1:58:28 PM4/13/12
to django...@googlegroups.com


On Friday, April 13, 2012 12:45:22 PM UTC-5, Timothy Makobu wrote:
Did you run a syncdb, then added mainloc after? Also, using south makes things much easier.

Of course I ran a syncdb. I have no experience with South and would like to solve this problem without using something else.


Thanks
  Alex
 
Hi all,

I am new to django and just learning, but for the current error I have absolutely no idea about the cause. I have created a model named Job in model.py which contains several elements. One of the is defined as follows:

    mainloc  = models.CharField(max_length=1, choices = MAINLOC)

and MAINLOC is a list of 2-tuples, with the first element a 1-character expression (like 'B', 'M'...). I have updated the database (the name mainloc is explicitly mentioned in the screen output), I have sync'd the database and restarted the server. But still, when I want to display the (empty) list on my browser, I get the message

   no such column: jobs_job.mainloc


Any idea or advice I could try to do?

Thanks
   Alex

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/4G24v1A5LaUJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

Timothy Makobu

unread,
Apr 13, 2012, 2:12:09 PM4/13/12
to django...@googlegroups.com
Right. The question is whether you added the field "after" running syncdb for the first time.

To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/mapjVj47xokJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.

alex3627

unread,
Apr 13, 2012, 2:33:07 PM4/13/12
to django...@googlegroups.com
Here is a repetition of what exactly I have done:

1. Add this field in my models.py

2. Run " python manage.py sql  jobs" (jobs is the name of the directory); in this step the field in question is explicitly written to stdout

3. Run "python manage.py syncdb"

4. Run "python manage.py runserver"

5. Go to the admin webpage to look at "jobs", and get this error.

Maybe I missed something? Or had the wrong order? Even if I repeat those steps I get the same result.


Alex



On Friday, April 13, 2012 1:12:09 PM UTC-5, Timothy Makobu wrote:
Right. The question is whether you added the field "after" running syncdb for the first time.

Daniel Roseman

unread,
Apr 13, 2012, 4:10:33 PM4/13/12
to django...@googlegroups.com
On Friday, 13 April 2012 19:33:07 UTC+1, alex3627 wrote:
Here is a repetition of what exactly I have done:

1. Add this field in my models.py

2. Run " python manage.py sql  jobs" (jobs is the name of the directory); in this step the field in question is explicitly written to stdout

3. Run "python manage.py syncdb"

4. Run "python manage.py runserver"

5. Go to the admin webpage to look at "jobs", and get this error.

Maybe I missed something? Or had the wrong order? Even if I repeat those steps I get the same result.


So, as Timothy says, you added since you originally ran syncdb.  The documentation[1] is clear that this doesn't work:
"Syncdb will not alter existing tables
syncdb will only create tables for models which have not yet been installed. It will never issue ALTER TABLE statements to match changes made to a model class after installation. Changes to model classes and database schemas often involve some form of ambiguity and, in those cases, Django would have to guess at the correct changes to make. There is a risk that critical data would be lost in the process.
If you have made changes to a model and wish to alter the database tables to match, use the sql command to display the new SQL structure and compare that to your existing table schema to work out the changes."

Or, as Timothy also said, use South.

--
DR.

alex3627

unread,
Apr 13, 2012, 4:25:06 PM4/13/12
to django...@googlegroups.com
Hi,

before even thinking to use 'South', I want to get it to work quick and quick. I don't care about existing databases, I have no information in the database anyway. Is there a way to just recreate a new, empty database from scratch? Really, remove the old database and create a new database so that it corresponds the one I have defined in models.py.


On the other side, I am not able to look at the database myself, because when trying to open it I get the error:

   ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Is there a way to access the database, and to possibly alter it, via "python manage.py shell"?


Thanks
  Alex

Daniel Roseman

unread,
Apr 13, 2012, 5:01:11 PM4/13/12
to django...@googlegroups.com
On Friday, 13 April 2012 21:25:06 UTC+1, alex3627 wrote:
Hi,

before even thinking to use 'South', I want to get it to work quick and quick. I don't care about existing databases, I have no information in the database anyway. Is there a way to just recreate a new, empty database from scratch? Really, remove the old database and create a new database so that it corresponds the one I have defined in models.py.

"manage.py reset" will drop and recreate all the tables.
 

On the other side, I am not able to look at the database myself, because when trying to open it I get the error:

   ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Is there a way to access the database, and to possibly alter it, via "python manage.py shell"?

"manage.py dbshell" will open the database shell with a connection to your DB.

-- 
DR. 

alex3627

unread,
Apr 13, 2012, 5:06:43 PM4/13/12
to django...@googlegroups.com
Finally that worked! Thanks a lot!


Alex
Reply all
Reply to author
Forward
Message has been deleted
0 new messages