Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Can someone give me an answer, even if the answer is "You can't" ?

Thanks Wayne

Last updated 2 years ago.
0

You can't not at this level.

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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'))
{
    //
}

http://laravel.com/docs/4.2/schema

Last updated 2 years ago.
0

Thanks sitesense, but not sure how that is relevant to this topic.

Last updated 2 years ago.
0

Little messy solution is try catch block of php it will not stop migration in case you drop not existing foreign. Hope that helps

0

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'); }

0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.