Hi Charles,
Thank you for your excellent library 馃檶
I'm trying to do some migrations by adding a ForeignKeyField, but I'm getting this error:
https://github.com/coleifer/peewee/blob/master/playhouse/migrate.py#L264
I couldn't find any documentation on what the rel_field is supposed to be.
with my_db.transaction():
migrate.migrate(
migrator.add_column('service', 'parent', peewee.ForeignKeyField(
db.ServiceCategory, null=True, on_delete='SET NULL'))
)
ValueError: Foreign keys must specify a `rel_field`.
rel_fieldwith my_db.transaction():
migrate.migrate(
migrator.add_column('service', 'parent', peewee.ForeignKeyField(
db.ServiceCategory, rel_field='servicecategory', null=True, on_delete='SET NULL'))
)
Traceback (most recent call last):
File "run.py", line 179, in <module>
db.migrations.run()
File "/Users/csytan/Documents/dev/cozycal/db/migrations/__init__.py", line 18, in run
importlib.import_module('db.migrations.{}'.format(version))
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/csytan/Documents/dev/cozycal/db/migrations/51.py", line 11, in <module>
db.ServiceCategory, rel_field='servicecategory', null=True, on_delete='SET NULL'))
File "/Users/csytan/Library/Python/3.6/lib/python/site-packages/peewee.py", line 4127, in __init__
super(ForeignKeyField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'rel_field'
The error message is out-of-date. The parameter name is "field" (no "rel_"). It refers to the field on the model your FK points to - typically the primary key.
# e.g., to reference the "id" field of ServiceCategory:
ForeignKeyField(db.ServiceCategory, db.ServiceCategory.id, null=True, on_delete='SET NULL')
Most helpful comment