qb question - is it not possible to add a foreign ...
# box-products
b
qb question - is it not possible to add a foreign key to a new integer column while altering schema? [SOLVED]
Copy code
function up( schema, qb ) {
		schema.alter( "tblServiceRates", function( table ) {
			table.addColumn( table.integer( "ResellerID" ).nullable() );

			table.foreignKey( "ResellerID" )
				.references( "ResellerID" )
				.onTable( "tblResellers" );
		} );
	}
The "ResellerID" column is created correctly, but no foreign key is attached to it
I'm doing what the docs say for this, though they're showing a schema create and I'm trying to alter schema: https://qb.ortusbooks.com/schema-builder/creating-table-constraints#foreignkey
ok, got it sorted. Needed to wrap that second call in
table.addConstraint()