DropForeignKey

The DropForeignKey method facilitates the dropping of an existing foreign-key constraint in the database.

Parameters

Parameter Description
i interface{} Accepts the go struct type of the table from which the foreign-key is being dropped. For example:If table column product.warehouse_id had a foreign-key constraint against table column warehouse.id, this parameter should be provided with go type Product{}.
ft string The database table name of the table on which the foreign-key is being dropped. For example:If table column product.warehouse_id had a foreign-key constraint against table column warehouse.id, this parameter should be provided with “product”.
fkn string The name of the foreign-key being dropped. For example:If table column product.warehouse_id has a foreign-key constraint against table.column warehouse.id, by convention this parameter should contain: “fk_product_warehouse_id”.
Sqac foreign-key naming convention can be found in the “fkey:” ‘sqac:’ tag documentation.

PublicDB.DropForeignKey Example

A sample call using the scenario described in the Parameters table follows:

...
// drop the foreign-key
err := Handle.DropForeignKey(Product{}, pn, "fk_product_warehouse_id")
...
...

DB Specific Notes

Database Notes
Sqlite3 SQLite does not permit ADD/DROP’s of foreign-key constraints on an existing table. As a result, sqac will simulate the dropping of a foreign-key constraint by executing the following steps: 1. Copying the existing table and it’s content to a temp DB table. 2. Dropping the existing table. 3. Recreating the table based on the “sqac:” tags declared in the go struct type contained in parameter i interface{}. 4. Loading the backed up table data from the temp table into the new table. 5. Dropping the temp table. This is not a fool-proof way of dealing with the situation, as the table in question may not have current or correct “sqac:” tags. Exercise caution using DropForeignKey with Sqlite3.