50646

Django 2.1 TypeError: __init__() got an unexpected keyword argument 'on_delete'

<h3>Question</h3>

My code:

class UserProfile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='profile') following = models.ManyToManyField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='followed_by') def __str__(self): return str(self.following.all().count())

My error:

TypeError: __init__() got an unexpected keyword argument 'on_delete'

Any ideas?


<h3>Answer1:</h3>

Looking at the docs, it seems that the field ManyToManyField does not have an argument called on_delete.

Remove that argument for the field following:

... user = models.OneToOneField( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='profile') following = models.ManyToManyField( settings.AUTH_USER_MODEL, related_name='followed_by') ...

来源:https://stackoverflow.com/questions/52312373/django-2-1-typeerror-init-got-an-unexpected-keyword-argument-on-delete

Recommend

  • Google map being returned in div tags via backbone javascript but not displaying
  • Message: element not visible when tring to click a checkbox through Selenium and Python
  • What is MySQL Collation, how to use it in practice?
  • ISNULL returns 0 for a hardcoded column with NULL value
  • gedit plugin error - plugin loader 'python3' was not found
  • Use block in Swift giving error “Variable used within its own initial value”
  • How to import JSON file on Jest tests?
  • ServiceStack JsonServiceClient - Custom HTTP Headers not sent
  • Is a C# struct ever boxed when used as the return value of a function?
  • WPF ToolBar Separator shrinks to nothing when inside a StackPanel
  • VBA Paste Value into new sheet below last row
  • An AppBar application not working correctly in Windows 8.x/10 (desktop working area does not get red
  • How to include prebuilt APK into AOSP with platform privileges
  • c++ plugin : Is it ok to pass polymorphic objects?
  • Parsing a complicated array with GetJSON Jquery
  • Angular 6 illegal operation on a directory, open '/Users//.npm-global/lib/node_modules/
  • Checking for valid enum types from protobufs
  • What are advantages/disadvantages of using Selenium for Java vs .NET applications?
  • Add checkbox dynamically using angular 2
  • how to run a different select statement based on condition in Hive SQL
  • openpyxl - adding new rows in excel file with merged cell existing
  • How do I use TagLib-Sharp to write custom (PRIV) ID3 frames?
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • convert json to excel in java
  • JavaScript RegExp Replace