Can someone give me an answer, even if the answer is "You can't" ?
Thanks Wayne
Thanks for the response. The more things I find I can't do the more it makes me question if this entire framework has just not had enough time to mature. Well I guess I will press forward anyhow.
Thanks again. Wayne
Documentation states:
"You may easily check for the existence of a table or column using the hasTable and hasColumn methods:"
if (Schema::hasTable('users'))
{
//
}
if (Schema::hasColumn('users', 'email'))
{
//
}
Thanks sitesense, but not sure how that is relevant to this topic.
Little messy solution is try catch block of php it will not stop migration in case you drop not existing foreign. Hope that helps
But we can still get to know whether an index is present or not, by an indirect approach
Solution :-
$conn = Schema::getConnection(); $dbSchemaManager = $conn->getDoctrineSchemaManager(); $doctrineTable = $dbSchemaManager->listTableDetails('table_name');
// You can also chain it // $doctrineTable = Schema::getConnection()->getDoctrineSchemaManager()->listTableDetails('table_name');
// alter table to remove an index if (! $doctrineTable->hasIndex('index_name')) { $table->dropIndex('index_name'); }
Hi
You can use this script:
IF EXISTS (SELECT *
FROM sys.foreign_keys
WHERE object_id = OBJECT_ID(N'[dbo].[FK_NAME]')
AND parent_object_id = OBJECT_ID(N'[dbo].[MyTable]'))
BEGIN
-- do stuff
END
Hope it helps you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community