Updating reference field "on delete" doesn't work


I tried this many times since I started with Wappler but now I really need to solve this, how do I update a reference field to set the “On delete” to a different value? It always gives an error message.

When setting up a new reference field with the right “On delete” it works, but I can’t delete the current field for a new field as it won’t work with the data I have already.

Please scroll down the error message on your 2nd screenshot and post it here, it might contain useful information

@Teodor Could you help please? Is this a bug?

  1. Is this on a local database?
  2. Can you erase the database and re-run the migrations?

It seems to me the migrations are not in sync with the actual database schema, because it’s atteempting to delete something it doesn’t exist in first place. If it’s a bug, it’s very likely it was something that occurred in the past. So, the best way to deal with this is to start with a fresh database and re-run the migrations and then do the new changes you want. Don’t forget to backup your data if you need it

Hi! Yes it’s on a local database. This error occurred since I started using Wappler so I don’t think that starting with a fresh database will solve the issue. Have you ever tried changing that field? Does it work for you?

Just tested it here, changed a reference field On Delete from No Action to Set Null, no errors

I’m using PostgreSQL

1 Like

I’m using PostgreSQL too. Is it possible to change that field manually with pgAdmin?

It’s an easy “fix” in the migration file, you can open the migration file and comment the line that says something like and re-run the migration:

// so it becomes like:
// table.dropForeign('xyz_id');

I didn’t mention this at first because this is a workaround to a problem that we don’t know if the core problem is fixed. If you do this you might be fixing the problem for the current database, but if you run the migrations in a new computer you might run into a similar issue. You do this at your own risk. The only way to be sure is to erase the current DB and re-run the migrations, which is my first suggested option

P.S.: On a side-note, have you tried to use Refresh Schema button? (not the icon), though make sure you delete any migration files that haven’t run succesfully


I’m using the local database to update the fields and then push the new changes to the production database. Does this mean that stuff in the production database (DO managed database) are not aligned as well? I don’t have experience in DB migrations etc so I’m afraid to cause even bigger problems trying to fix this issue…

Can you use a program like DBeaver to make a backup of your local database, and then you erase all tables, restart Wappler and re-run the migrations and optionally restore the data you backed up?

The remote database may be aligned with the migrations, but it seems your local database might not. So, if you apply the above fix to fix the local DB, you could risk misaligning the remote DB, although it’s not a catastrophic scenario - the migration would likely fail to run, and you’d have to revert the changes you’ve made to the migration file.

The local database could be misaligned because you attempted to create a migration when Wappler wasn’t in sync with the local schema, but this is speculation at this point

1 Like

Ok thank you will try that now. Can you explain please how the “re-run the migrations” work? Does that happen automatically when I refresh the schema or something?

Check this post of mine:

It’s the apply latest changes button

Good luck!

1 Like