Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries
You can change the property categorie
of the class Article
like this:
categorie = models.ForeignKey(
'Categorie',
on_delete=models.CASCADE,
)
and the error should disappear.
Eventually you might need another option for on_delete
, check the documentation for more details:
Arguments -- Model field reference -- Django documentation
As you stated in your comment, that you don't have any special requirements for on_delete
, you could use the option DO_NOTHING
:
# ...
on_delete=models.DO_NOTHING,
# ...
__init__() missing 1 required positional argument
You're receiving this error because you did not pass a data
variable to the DHT constructor.
aIKid and Alexander's answers are nice but it wont work because you still have to initialize self.data
in the class constructor like this:
class DHT:
def __init__(self, data=None):
if data is None:
data = {}
else:
self.data = data
self.data['one'] = '1'
self.data['two'] = '2'
self.data['three'] = '3'
def showData(self):
print(self.data)
And then calling the method showData like this:
DHT().showData()
Or like this:
DHT({'six':6,'seven':'7'}).showData()
or like this:
# Build the class first
dht = DHT({'six':6,'seven':'7'})
# The call whatever method you want (In our case only 1 method available)
dht.showData()
Error when trying to override __init__() : TypeError: __init__() takes 1 positional argument but 2 were given
Every class init
method has self
as an argument to allow adding attributes to this newly created instance of the class.
Calling super().__init__(self, **kwargs)
in Child.init
results to Base(Child, **kwargs)
. The base constructor takes only one argument so an error is raised.
TypeError: __init__() missing 2 required positional arguments: 'client_socket' and 'statusMessage'
class SimpleClient:
def __init__(self, client_socket, statusMessage):
Your class taking two arguments, but when you call it;
client = SimpleClient()
You didn't write any arguments. So you have to put 2 arguments they may be None
.
Related Topics
Rotate Image and Crop Out Black Borders
Extract Day of Year and Julian Day from a String Date
Str.Startswith with a List of Strings to Test For
How to Read a Column of CSV as Dtype List Using Pandas
Format Strings VS Concatenation
How to Do Row-To-Column Transposition of Data in CSV Table
Check If Value Already Exists Within List of Dictionaries
Can a Decorator of an Instance Method Access the Class
Installing MySQLclient in Python 3.6 in Windows
Is There a Multi-Dimensional Version of Arange/Linspace in Numpy
Convert List into a Dictionary
How to Install the Yaml Package for Python
Value Error Trying to Install Python for Windows Extensions
List All Base Classes in a Hierarchy of Given Class
Putting Many Python Pandas Dataframes to One Excel Worksheet