How to change the name of a third party app on Django? - python

I am using django-allauth and its account app conflicts with my account app.
I managed to fix this conflict by creating an app label for allauth.account based on this solution
from django.apps import AppConfig
class AllAuthAccountConfig(AppConfig):
name = 'allauth.account'
label = 'allauth_account'
verbose_name = 'aullauth_account'
and then adding it to installed apps
INSTALLED_APPS = (
...,
'apps.allauth.apps.AllAuthAccountConfig',
...,
)
Now, when I try to migrate it gives an error
CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0001_initial, 0002_email_max_length in allauth_account).
To fix them run 'python manage.py makemigrations --merge'
but python manage.py makemigrations --merge also fails with the following error:
ValueError: Could not find common ancestor of ['0001_initial', '0002_email_max_length']
How can I change the allauth.account app name so it doesn't conflict with my app or my migations?

you can use django rename app package package link. I have never use it personally but it seems to be good. you can try it

Related

ModuleNotFoundError : no module found named <module_name>django

I am trying to make a web application using django. so in the website folder, I made another app named U0.
I made sure to add it in the settings section of the website. but when I try to migrate the manage.py file it throws an error saying, No Module found named U0django
In order to create a new app in Django, you have to use the Django builtin command to create the correct structure of an app for you like this:
django-admin startapp u0
btw I believe if you want to create it on your own you have to create a file named apps.py in your app folder and add these lines to that to help Django identify it as an app :
from django.apps import AppConfig
class U0(AppConfig):
name = 'u0'

python manage.py makemigrations : No changes detected

I am working on a project using django and I am using pycharm software. In my 'store' directory i have a python package called 'models' in which there are two python files :- init.py and product.py . The problem i am getting is that I cannot create table using the command even when I am importing the 'Product' class from product module in init.py file. Even both the modules are also in the same package.
Here is the code of the product.py file:-
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=50)
price = models.IntegerField(default=0)
description = models.CharField(max_length=200, default='')
image = models.ImageField(upload_to='products/')
And here is the code of init.py file:-
from .product import Product
But when i am running the command on terminal i am getting this error:-
(venv) C:\Users\Admin\PycharmProjects\SMart>python manage.py makemigrations
No changes detected
You must put the name of your app <store> into the list of INSTALLED_APPS inside your settings.
I had the same issue with Django 4. To solve it, I created migrations/__init__.py file in every app directory. So just run these command for every app:
mkdir appname/migrations
touch appname/migrations/__init__.py
Then use manage.py:
python3 manage.py makemigrations
python3 manage.py migrate
And it worked.

Django - app in subfolder

I've created new django app in a subdirectory using the command:
python manage.py startapp appName subFolder/appName
but if I try to add this app to INSTALLED_APPS at the end of the list I see the following error:
ImportError: No module named appName
Does anyone know what I am doing wrong?
You need to include the subfolder when you add the app to INSTALLED_APPS, for example:
'subFolder.appName',
or
'subfolder.appName.apps.AppNameConfig',
I tried different options but no one can solve that issue.
Finally, I found a solution.
Simply go to the subFolder/appName/app.py file and
replace this line name = 'appname' with name = 'subfolder.appname'
And then you can simply add to the installed apps list.
'subfolder.appname'

Django 1.7 loads extraneous models when running tests

I have a Django project that worked well with Django 1.6, but is giving me a lot of trouble as I try to upgrade to Django 1.7.
In this project is an app, my_app which does not contain any models of its own, but contains a file other_models.py, generated to interact with a legacy database using python manage.py inspectdb. I want to use these models only in specific code paths, when I'm connected to a this secondary database. Again, this worked fine with Django 1.6.
Having upgraded to Django 1.7, I am no longer able to run my test suite using python manage.py test. When I do this, I get a huge number of errors that look like the following:
CommandError: System check identified some issues:
ERRORS:
my_app.AccountAccount.created_by_type: (fields.E304) Reverse accessor for 'AccountAccount.created_by_type' clashes with reverse accessor for 'AccountAccount.deactivated_by_type'.
HINT: Add or change a related_name argument to the definition for 'AccountAccount.created_by_type' or 'AccountAccount.deactivated_by_type'.
...
# Tons more of these
These errors are all complaining about models defined in other_models.py. It appears to me that the changes in app-loading process are causing my problems, but I'm not entirely sure.
I have tried setting up an apps.py in this app with the following code:
from django.apps import AppConfig
class MyAppConfig(AppConfig):
name = 'my_app'
models_module = None
and added default_app_config = 'my_app.apps.MyAppConfig' to my my_app.__init__.py, as per the documentation on configuring applications, but to no avail.
I'm at a total loss for what to do next, and would appreciate any information regarding how to control when and how Django attempts to load models, especially when running python manage.py test.

Django 1.7 - makemigrations not detecting changes - managed models

I have just installed django 1.7 in my virtual env.
Then I manually created the following files:
service_bus/
service_bus/__init__.py
service_bus/django_settings.py
service_bus/models
service_bus/models/__init__.py
service_bus/models/dsp.py
service_bus/models/audience_type.py
service_bus/models/category.py
service_bus/models/audience.py
service_bus/models/dsp_config.py
service_bus/models/apsettings.py
So I have a settings file service_bus/django_settings.py and the service_bus app.
Then I did, on bash:
export DJANGO_SETTINGS_MODULE='service_bus.django_settings'
Then I just try to run makemigrations, but it says no changes are detected.
$ django-admin makemigrations
Loading properties from /etc/s1mbi0se/dmp.ini
System check identified some issues:
WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
No changes detected
$ django-admin makemigrations service_bus
Loading properties from /etc/s1mbi0se/dmp.ini
System check identified some issues:
WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
No changes detected in app 'service_bus'
In all my models I have something like
class APSettings(models.Model):
...
class Meta:
db_table = u'APSettings'
app_label = 'service_bus'
What could I be missing?
You need to run the migrate command first to scaffold the database schema. Then, you can run makemigrations for each app. Check the Django tutorial for more on this.
Make sure you update your models.py file to actually import the models. For example in models.py you'd have from service_bus.models.audience import *. The manage script goes over that file, imports all the models in audience.py and detects changes in there. If you did not add your new models to models.py then the manage script won't know about the new models in you models files.

Categories