question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CustomCountryModel not working

See original GitHub issue

Checklist

  • I have verified that I am using a GIS-enabled database, such as PostGIS or Spatialite.
  • I have verified that that issue exists against the master branch of django-cities.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

Fresh install, add CustomCountryModel as it is in the example from django-cities, run makemigrations.

INSTALLED_APPS = (
    ...
    # I tried both order
    'myapp',
    'cities',
)

Environment: Python 3.5.2 Django==1.10.5 django-cities==0.5.0.3 ( installed from github, branch master )

Expected behavior

I think it should do the migration files 😃

Actual behavior

host:~#./manage.py makemigrations

SystemCheckError: System check identified some issues:

ERRORS:
<myapp>.CustomCountryModel.alt_names: (fields.E300) Field defines a relation with model 'AlternativeName', which is either not installed, or is abstract.
<myapp>.CustomCountryModel.alt_names: (fields.E307) The field <myapp>.CustomCountryModel.alt_names was declared with a lazy reference to '<myapp>.alternativename', but app '<myapp>' doesn't provide model 'alternativename'.
<myapp>.CustomCountryModel_alt_names.alternativename: (fields.E307) The field <myapp>.CustomCountryModel_alt_names.alternativename was declared with a lazy reference to '<myapp>.alternativename', but app '<myapp>' doesn't provide model 'alternativename'.

For a quick fix I moved the AlternativeNames model above Place and removed the lazy reference of AlternativeName

Let me know if you need more details.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:22

github_iconTop GitHub Comments

1reaction
AlexProficommented, Jul 31, 2017

all this variants not work only variant with swapper in meta work without add to settings file CITIES_COUNTRY_MODEL = ‘geo.CustomCountryModel’ but there are no custom fields in model may be migrations made by django wrong

-- coding: utf-8 --

Generated by Django 1.10 on 2017-07-31 16:44

from future import unicode_literals

from django.conf import settings from django.db import migrations, models import django.db.models.deletion

class Migration(migrations.Migration):

initial = True

dependencies = [
    migrations.swappable_dependency(settings.CITIES_CONTINENT_MODEL),
    ('cities', '0012_auto_20170731_1926'),
    migrations.swappable_dependency(settings.CITIES_COUNTRY_MODEL),
]

operations = [
    migrations.CreateModel(
        name='CustomCountryModel',
        fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ('slug', models.CharField(blank=True, max_length=255, null=True)),
            ('name', models.CharField(db_index=True, max_length=200, verbose_name='ascii name')),
            ('code', models.CharField(db_index=True, max_length=2, unique=True)),
            ('code3', models.CharField(db_index=True, max_length=3, unique=True)),
            ('population', models.IntegerField()),
            ('area', models.IntegerField(null=True)),
            ('currency', models.CharField(max_length=3, null=True)),
            ('currency_name', models.CharField(blank=True, max_length=50, null=True)),
            ('currency_symbol', models.CharField(blank=True, max_length=31, null=True)),
            ('language_codes', models.CharField(max_length=250, null=True)),
            ('phone', models.CharField(max_length=20)),
            ('tld', models.CharField(max_length=5, verbose_name='TLD')),
            ('postal_code_format', models.CharField(max_length=127)),
            ('postal_code_regex', models.CharField(max_length=255)),
            ('capital', models.CharField(max_length=100)),
            ('more_data', models.TextField()),
            ('alt_names', models.ManyToManyField(to='cities.AlternativeName')),
            ('continent', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='countries', to=settings.CITIES_CONTINENT_MODEL)),
            ('neighbours', models.ManyToManyField(related_name='_customcountrymodel_neighbours_+', to=settings.CITIES_COUNTRY_MODEL)),
        ],
        options={
            'verbose_name_plural': 'countries',
            'swappable': 'CITIES_COUNTRY_MODEL',
            'abstract': False,
            'ordering': ['name'],
        },
    ),
]

more_data field exists in migration but not in db

1reaction
blagcommented, Apr 11, 2017

Dang, I was hoping it would be an easy fix.

If you make a PR with your changes I’ll review it and merge it in.

As for making sure this doesn’t break in the future, since these issues were caught by Django’s checks framework, I’m thinking I can just make an app with custom/swapped models and run Django’s check management command.

Read more comments on GitHub >

github_iconTop Results From Across the Web

django-cities - Bountysource
The import seems to have some serious reliability issues. While I'm sure some of these aren't due to cities doing the wrong thing....
Read more >
[Help] Simple Form gem and custom Country model list not ...
I've got two models that I want to use for select questions in a Simple Form form (Audience and Country). Both have data...
Read more >
Django 1.5 custom User model error. "Manager isn't available
But below config seem work for me with latest Dev version. Model.py: class CustomUser(AbstractUser): custom_field = models.ForeignKey(' ...
Read more >
django-cities - Python Package Health Analysis - Snyk
The python package django-cities was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as...
Read more >
intl-input-phone - npm
Start using intl-input-phone in your project by running `npm i ... in dropdown as well or not, when specify custom country list in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found