django-getpaid won't migarte in new project
See original GitHub issue- django-getpaid version: 2.2.2
- Django version: 3.2.3
- Python version: 3.8
- Operating System: macOS
Description
As I’ve created new project and I wanted to use django-getpaid I’ve just installed it with poetry, defined an Order instance and tried to migrate the app.
Result:
$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/commands/makemigrations.py", line 172, in handle
changes = autodetector.changes(
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/autodetector.py", line 41, in changes
changes = self._detect_changes(convert_apps, graph)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/autodetector.py", line 126, in _detect_changes
self.old_apps = self.from_state.concrete_apps
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/state.py", line 212, in concrete_apps
self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/state.py", line 277, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field getpaid.Payment.order was declared with a lazy reference to 'backend.order', but app 'backend' doesn't provide model 'order'.
Definition of an Order model:
class Order(AbstractOrder):
items = models.ManyToManyField("Product", related_name='items', through="OrderItem")
description = models.CharField(max_length=128)
buyer_email = models.EmailField()
buyer_phone = models.CharField(max_length=12)
def is_ready_for_payment(self):
pass
def get_total_amount(self):
final = Decimal(0)
for order_item in self.items.all():
final += order_item.item.final_price_with_tax * order_item.amount
return final
def get_buyer_info(self):
return {"email": self.buyer_email, "phone": self.buyer_phone}
def get_currency(self):
return "PLN"
def get_description(self):
return self.description
settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'getpaid',
'getpaid_payu', # one of plugins
'rest_framework',
'backend.apps.BackendConfig',
'corsheaders',
]
GETPAID_ORDER_MODEL = 'backend.Order'
GETPAID_BACKEND_SETTINGS = {
"getpaid_payu": {
# take these from your merchant panel:
"pos_id": os.getenv('PAYU_POS_ID'),
"second_key": os.getenv("PAYU_SECOND_KEY"),
"oauth_id": os.getenv('PAYU_OAUTH_ID'),
"oauth_secret": os.getenv("PAYU_OAUTH_SECRET"),
},
}
What I Did
Recreate an database and migrations
Result: Fail, django-getpaid requires at least one migration to run. Traceback
$ python manage.py migrate backend
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 92, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/loader.py", line 259, in build_graph
self.graph.validate_consistency()
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/graph.py", line 195, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/graph.py", line 195, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/Users/mateusz/Library/Caches/pypoetry/virtualenvs/drop-OdaMbioT-py3.8/lib/python3.8/site-packages/django/db/migrations/graph.py", line 58, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration getpaid.0001_initial dependencies reference nonexistent parent node ('backend', '0001_initial')
Core code modifications
Result: success, but after following steps:
- I’ve commented these lines in
getpaid/models.py
class Payment(AbstractPayment):
class Meta(AbstractPayment.Meta):
swappable = swapper.swappable_setting("getpaid", "Payment")
after what I’ve received
RuntimeError: Model class getpaid.models.Payment doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
so I’ve commented get_paid
in INSTALLED_APPS
- Migrate my app once, so I have an Order in my schema
- Uncomment the Payment model in the app and
getpaid
inINSTALLED_APPS
- Migrated it once again.
Summary
Actually I’m not sure if I did not broke something, I’ll update you guys after some tests, but anyway, did I do something wrong? I actually followed the documentation, so If it’s my fault maybe docs update should be considered?
Have great day, Mat.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
python - Django 1.7 - "No migrations to apply" when run ...
"This will make a new initial migration for your app. Now, when you run migrate, Django will detect that you have an initial...
Read more >Migrations - Django documentation
Migrations¶. Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database...
Read more >How to solve broken migration history in Django - Dev Genius
If some migrations of that app were deleted and the history of the migrations was broken, one solution is to clear the migration...
Read more >How to Move a Django Model to Another App - Real Python
There are several ways to move a Django model from one app to another using Django migrations, but unfortunately none of them are...
Read more >makemigration and migrate doesn't work docker production
Your models have changes that are not yet reflected in a migration, and so won't be applied. Run "manage.py makemigrations" to make new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, I’ll use your
test_project
to investigate it further. Thanks!Hi @dekoza thanks for blazing fast response! The thing is that even with initial migration it does not goes through. Check this example repo: https://github.com/BuSSioR/getpaid_issue_example/ After
python manage.py migrate
it throws:and
show_migrations
after I commentget_paid
fromINSTALLED APPS
andMyCustomOrder
shows that every other migration is in place