50
loading...
This website collects cookies to deliver better user experience
ALTER TABLE
sql statement to drop a foreign key in sqlite. To do that, you will have to rename the table, create a new table without the foreign key, and then copy the data into the new table.changes
and droppings
through out the lifetime of your project.TestCase
class, create a function that calls the Connection
class resolverFor
method. It takes the driver's name as the first parameter and a callback as the second.SQLiteConnection
and override the getSchemaBuilder
method:public function hotfixSqlite()
{
\Illuminate\Database\Connection::resolverFor('sqlite',
function ($connection, $database, $prefix, $config) {
return new class($connection, $database, $prefix, $config)
extends SQLiteConnection {
public function getSchemaBuilder()
{
if ($this->schemaGrammar === null) {
$this->useDefaultSchemaGrammar();
}
return new class($this) extends SQLiteBuilder {
protected function createBlueprint($table, Closure $callback = null)
{
return new class($table, $callback) extends Blueprint {
public function dropForeign($index)
{
return new Fluent();
}
};
}
};
}
};
});
}
TestCase
's constructor class. Your final TestCase
class should look like the following:abstract class TestCase extends BaseTestCase
{
public function __construct(?string $name = null, array $data = [], string $dataName = '')
{
$this->hotfixSqlite();
parent::__construct($name, $data, $dataName);
}
/**
*
*/
public function hotfixSqlite()
{
\Illuminate\Database\Connection::resolverFor('sqlite',
function ($connection, $database, $prefix, $config) {
return new class($connection, $database, $prefix, $config)
extends SQLiteConnection {
public function getSchemaBuilder()
{
if ($this->schemaGrammar === null) {
$this->useDefaultSchemaGrammar();
}
return new class($this) extends SQLiteBuilder {
protected function createBlueprint($table, Closure $callback = null)
{
return new class($table, $callback) extends Blueprint {
public function dropForeign($index)
{
return new Fluent();
}
};
}
};
}
};
});
}
}
This post appeared here first.