django 1.9, migrations SUCK

935 views
Skip to first unread message

Jorge Cadena

unread,
Jul 29, 2016, 10:07:33 AM7/29/16
to Django users
Hi,

I am dev in django at last 4 years, i missed ./manage.py syncdb,

Delete all tables from databases (MariaDB, PostgreSQL) command line from DB, and run python manage.py migrate always same error

python manage.py migrate
django.db.utils.ProgrammingError: (1146, "Table 'dashaboard_web.did_didcountry' doesn't exist")

python manage.py migrate did
django.db.utils.ProgrammingError: (1146, "Table 'dashaboard_web.did_didcountry' doesn't exist")

python manage.py makemigrations
django.db.utils.ProgrammingError: (1146, "Table 'dashaboard_web.did_didcountry' doesn't exist")

python manage.py sqlmigrate did 0001
django.db.utils.ProgrammingError: (1146, "Table 'dashaboard_web.did_didcountry' doesn't exist")

python manage.py migrate --run-syncdb
django.db.utils.ProgrammingError: (1146, "Table 'dashaboard_web.did_didcountry' doesn't exist")


if the tables doesn't exist, why create table new ???
as, create new tables run command python manage.py migrate ??

Michal Petrucha

unread,
Jul 29, 2016, 10:25:31 AM7/29/16
to django...@googlegroups.com
On Fri, Jul 29, 2016 at 07:02:44AM -0700, Jorge Cadena wrote:
> Hi,
>
> I am dev in django at last 4 years, i missed ./manage.py syncdb,
>
> Delete all tables from databases (MariaDB, PostgreSQL) command line from
> DB, and run python manage.py migrate always same error
>
> *python manage.py migrate*
> django.db.utils.ProgrammingError: (1146, "Table
> 'dashaboard_web.did_didcountry' doesn't exist")
>
> *python manage.py migrate did*
> django.db.utils.ProgrammingError: (1146, "Table
> 'dashaboard_web.did_didcountry' doesn't exist")
>
> *python manage.py makemigrations*
> django.db.utils.ProgrammingError: (1146, "Table
> 'dashaboard_web.did_didcountry' doesn't exist")
>
> *python manage.py sqlmigrate did 0001*
> django.db.utils.ProgrammingError: (1146, "Table
> 'dashaboard_web.did_didcountry' doesn't exist")
>
> *python manage.py migrate --run-syncdb*
> django.db.utils.ProgrammingError: (1146, "Table
> 'dashaboard_web.did_didcountry' doesn't exist")
>
>
> if the tables doesn't exist, why create table new ???
> as, create new tables run command python manage.py migrate ??

If you're getting errors about missing database tables even when you
run manage.py makemigrations, then that would mean you'll get that
same error every time you run manage.py, regardless of what command
you run. makemigrations does not access the database, it only inspects
existing migration files, and compares them to the current model
definitions.

The error you are getting is most likely because you're accessing the
database on import (i.e. somewhere at module level you are making
database queries). If that is indeed the case, then you would get the
exact same error even with the old syncdb. However, it is hard to tell
for sure, since you have not provided the full traceback.

Cheers,

Michal
signature.asc

Jorge Cadena

unread,
Jul 29, 2016, 10:44:05 AM7/29/16
to Django users
same error, in mariaDB, postgresql, rigth now in sqlite3

Jorge Cadena

unread,
Jul 29, 2016, 11:12:20 AM7/29/16
to Django users

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 398, in execute
self.check()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/ariatel_web/dashboard.ariatel.com.co/dashaboar_ariatel/urls.py", line 20, in <module>
from apps.did.views import CountryViewSet, AreasViewSet
File "/home/ariatel_web/dashboard.ariatel.com.co/apps/did/views.py", line 15, in <module>
from .forms import BuySearchForm
File "/home/ariatel_web/dashboard.ariatel.com.co/apps/did/forms.py", line 11, in <module>
class BuySearchForm(forms.Form):
File "/home/ariatel_web/dashboard.ariatel.com.co/apps/did/forms.py", line 12, in BuySearchForm
country = forms.ChoiceField(choices=[ (d.country_name, d.country_name) for d in DidCountry.objects.filter(is_active=True) ], required=False)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 323, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: did_didcountry

Daniele Procida

unread,
Jul 29, 2016, 11:16:57 AM7/29/16
to Django Users
On Fri, Jul 29, 2016, Jorge Cadena <jorge....@gmail.com> wrote:

>I am dev in django at last 4 years, i missed ./manage.py syncdb,

Please change your email subject to something more polite.

You have a good chance to get expert help here from people, including perhaps people who helped create the Django migrations system - don't be rude about it.

Daniele

Michal Petrucha

unread,
Jul 29, 2016, 11:17:39 AM7/29/16
to django...@googlegroups.com
This line here is the problem – you should never evaluate querysets at
module level, in this case you should either use a function as the
choices argument to ChoiceField, or use a ModelChoiceField.
signature.asc

Vijay Khemlani

unread,
Jul 29, 2016, 12:36:57 PM7/29/16
to django...@googlegroups.com
  File "/home/ariatel_web/dashboard.ariatel.com.co/apps/did/forms.py", line 12, in BuySearchForm
    country = forms.ChoiceField(choices=[ (d.country_name, d.country_name) for d in DidCountry.objects.filter(is_active=True) ], required=False)

Theres your problem, you are trying to query the database when it's empty

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/36188b9a-c477-4b9e-aa75-1c7f915e3cac%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ludovic coues

unread,
Jul 29, 2016, 12:37:27 PM7/29/16
to django...@googlegroups.com
In /home/ariatel_web/dashboard.ariatel.com.co/apps/did/forms.py, replacing
country = forms.ChoiceField(choices=[ (d.country_name,
d.country_name) for d in DidCountry.objects.filter(is_active=True) ]

with
country = forms.ChoiceField(choices=lambda: [ (d.country_name,
d.country_name) for d in DidCountry.objects.filter(is_active=True) ]

should do the trick. It will make the choices arguments a callable
which will be evaluated when the form is used for the first time, not
when the module is imported.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/36188b9a-c477-4b9e-aa75-1c7f915e3cac%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Aztrock

unread,
Jul 29, 2016, 4:21:35 PM7/29/16
to django...@googlegroups.com
Excellent, thanks

This method i use from django 1.4, never have problem.



--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/qqvMiE35EGg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
Un hombre de carácter podrá ser derrotado pero jamás destruido.

ERNEST HEMINGWAY.

Tom Evans

unread,
Aug 3, 2016, 10:11:47 AM8/3/16
to django...@googlegroups.com
On Fri, Jul 29, 2016 at 9:19 PM, Aztrock <jorge....@gmail.com> wrote:
> Excellent, thanks
>
> This method i use from django 1.4, never have problem.
>

Apart from having to restart your application server each time you
added a country, sure, no problems.

Cheers

Tom

Tom Christie

unread,
Aug 3, 2016, 10:17:01 AM8/3/16
to Django users
I'd suggest using `country = forms.ChoiceField(choices=[])` in the form declaration itself, and having the form `__init__()` method populate the *actual* set of choices. That way the allowable set of choices will always reflect whats currently in the DB at the point that the view runs.

ludovic coues

unread,
Aug 3, 2016, 6:36:35 PM8/3/16
to django...@googlegroups.com
Or, you could read either this thread or the doc and take advantage of
the django taking care of you.
Quoting the doc: "If the [choice] argument is a callable, it is
evaluated each time the field’s form is initialized."
That's why I suggested to add "lambda: " before the list
comprehension. To turn the value into a callable.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/288ec271-0118-46f5-93ba-089343e11cf9%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages