simonw / datasette-edit-schema

Datasette plugin for modifying table schemas
Apache License 2.0
16 stars 0 forks source link

500 error if a table has only primary keys #51

Closed simonw closed 7 months ago

simonw commented 7 months ago

I have a m2m table that has a primary key across both columns.

When I tried to edit the schema I got a 500 error. Sentry says:

CleanShot 2024-02-08 at 15 25 38@2x

simonw commented 7 months ago

Relevant code: https://github.com/simonw/datasette-edit-schema/blob/d6a7099bf529c0d29ddceec7d1764a750100e336/datasette_edit_schema/utils.py#L54-L76

Called from here: https://github.com/simonw/datasette-edit-schema/blob/d6a7099bf529c0d29ddceec7d1764a750100e336/datasette_edit_schema/__init__.py#L477-L483

simonw commented 7 months ago

Created a manual test DB like this:

echo '{"one": 1, "two": 2}' | sqlite-utils insert two_pks.db two_pks --pk one --pk two -

And this so I can test foreign key creation:

echo '{"one": 1, "two": 2}' | sqlite-utils insert two_pks.db other --pk one -
simonw commented 7 months ago

Fixed this problem but found you cannot set a primary key as a foreign key reference, which prevents you from using this plugin to create a m2m table with foreign key references. I'll fix that in a separate issue.