Error while migrating in Laravel database on heroku - postgresql

When running heroku run php artisan migrate I get this error, I want to host my app on heroku
In Connection.php line 712
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "price" cannot be cast automatically to type numeric
HINT: You might need to specify "USING price::numeric(15,2)". (SQL: ALTER TABLE purchases ALTER price TYPE NUMERIC
(15, 2))
In Connection.php line 501:
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "price" cannot be cast automatically to type numeric
HINT: You might need to specify "USING price::numeric(15,2)".
purchase table
lass ChangePurchasePriceDataTyp extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('purchases', function (Blueprint $table) {
$table->numeric('price',15,2)->unsigned()->default(0)->change();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('purchases', function (Blueprint $table) {
//
});
}
}
database.php
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => isset($DATABASE_URL['host']) ? $DATABASE_URL['host'] : null,
'port' => isset($DATABASE_URL['port']) ? $DATABASE_URL['port'] : null,
'database' => isset($DATABASE_URL['path']) ? ltrim($DATABASE_URL['path'], "/") : null,
'username' => isset($DATABASE_URL['user']) ? $DATABASE_URL['user'] : null,
'password' => isset($DATABASE_URL['pass']) ? $DATABASE_URL['pass'] : null,
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
what could be wrong? initial the datatype was decimal but I changed it to numeric

Related

TYPO3 9.5 second database - Errors in ExtensionManager

I have a problem when adding a second third party Oracle database to the TYPO3 Configuration in a TYPO3 9.5. After adding the configuration I cannot install any extensions (including core extensions) in ExtensionManager anymore.
In LocalConfiguration.php I add a second database (it's the database of a patent management system - no "TYPO3 style"):
'DB' => [
'Connections' => [
'Default' => [
....
],
'MyDB' => [
'charset' => 'utf8',
'dbname' => 'xxx',
'driver' => 'oci8',
'host' => 'xxx',
'password' => 'xxx',
'port' => '1521',
'user' => 'xxx',
],
],
'TableMapping' => [
'SCHEMA.TABLE1' => 'MyDB'
],
'extTablesDefinitionScript' => 'extTables.php',
],
I use QueryBuilder in the action in my controller and I can query the table without any problems.
BUT installing any extension in ExtensionManager leads to the following error:
(1/1) TypeError
Argument 1 passed to TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener::getDatabaseType() must be of the type string, null given, called in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php on line 41
in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php line 93
*
* #param string $typeDefiniton
* #return string
*/
protected function getDatabaseType(string $typeDefiniton): string
{
$dbType = strtolower($typeDefiniton);
$dbType = strtok($dbType, '(), ');
at TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener->getDatabaseType(null)
in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php line 41
public function onSchemaColumnDefinition(SchemaColumnDefinitionEventArgs $event)
{
$tableColumn = $event->getTableColumn();
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
$dbType = $this->getDatabaseType($tableColumn['type']);
if ($dbType !== 'enum' && $dbType !== 'set') {
return;
}
at TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener->onSchemaColumnDefinition(object(Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs))
As soon as I remove the second database from LocalConfiguration.php the ExtensionManager is working again - but of course the QueryBuilder does not know the table any more :enttäuscht:

Yii2 and postgres connecttion

I tried yii2 and postgres database but when I try to query my table i got an error . How to fix this?
LINK for my error:
LINK for my database connection:
maybe you don't set defaultSchema on connection string
return [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;dbname=db_name',
'username' => 'db_username',
'password' => 'db_password',
'charset' => 'utf8',
'schemaMap' => [
'pgsql'=> [
'class'=>'yii\db\pgsql\Schema',
'defaultSchema' => 'public' //specify your schema here
]
], // PostgreSQL
];
see to here
OR
change your tableName() function in model like this
/**
* #inheritdoc
*/
public static function tableName()
{
return 'schemaName.table_name';
}

how to use auto_increment in fuelphp to create table

I write a fileds like this
$fileds = array(
'id' => array('type' => 'integer','AUTO_INCREMENT'=>true),
'user' => array('type' => 'text'),
'time' => array('type' => 'integer')
);
When I run thisDBUtil::create_table($table, $fileds);
it turn wrong,
exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 near "AUTO_INCREMENT": syntax error' in /home/yangjun/phpenv/public_html/cmanage/fuel/core/classes/database/pdo/connection.php:239
What is wrong ?
ihave rewrite a new test,and add primary key,but doesn't work,i read the document in fuelphp,no idea~
<?php
/**
* #group test
*/
class Test extends TestCase
{
public static function setUPBeforeClass()
{
DBUtil::set_connection('request');
$table = 'test';
$fileds = array(
'_id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
'_name' => array('type' => 'test'),
'_data' => array('type' => 'test')
);
$primary_keys = array('_id');
DBUtil::create_table($table, $fileds, $primary_keys);
}
public function test_add_keycode_request()
{
$RequestData = array(
'_id' => '',
'_name' => 'hhh',
'_data' => 'ggg');
$RequestData1 = array(
'_id' => '',
'_name' => 'hhhh',
'_data' => 'gggg');
self::add_request($RequestData);
self::add_request($RequestData1);
Cli::write(__METHOD__ . " √ \n", 'green');
}
public static function add_request($RequestData)
{
try {
$result = \DB::insert('test')
->set($RequestData)
->execute('request');
} catch (\Database_Exception $e) {
\Log::error('DB access Error' . $e);
throw $e;
}
return $result;
}
}
error log,this is whole error log,synatax error?
Test
1.exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 near "AUTO_INCREMENT": syntax error' in /home//phpenv/public_html/fuel/core/classes/database/pdo/connection.php:239
2.Next exception 'Fuel\Core\Database_Exception' with message 'SQLSTATE[HY000]: General error: 1 near "AUTO_INCREMENT": syntax error with query: "CREATE TABLE IF NOT EXISTS "test" (
"_id" int(11) NOT NULL AUTO_INCREMENT,
"_name" test NOT NULL,
"_data" test NOT NULL,
PRIMARY KEY "_id" ("_id"));"' in /home/yangjun/phpenv/public_html/fuel/core/classes/database/pdo/connection.php:272
Seems is missing the constraint param on columns field (i don't know also if int or integer type field).
Try this:
$fileds = array(
'id' => array('constraint' => 11,'type' => 'integer','AUTO_INCREMENT'=>true),
'user' => array('type' => 'text'),
'time' => array('constraint' => 11, 'type' => 'integer'))
}
UPDATE
Need to specify the primary key also:
DBUtil::create_table($table, $fileds, array('id'));
More info in the doc here
Hope this help

In CakePHP am getting this error: "Fixture invalid: Count of fields does not match count of values"

When I am running test cases I am getting the above error: "Fixture invalid: Count of fields does not match count of values".
Can anyone say why I would be getting that? And how to fix it?
I must note that for my fixtures, I am automatically importing the table definition like so:
/**
* Import table definition
*
* #var string
*/
public $import = 'Category';
/**
* Records
*
* #var array
*/
public $records = array(
array(
'id' => 1,
'name' => 'Science',
'post_count' => 0
),
array(
'id' => 2,
'name' => 'Information Technology',
'post_count' => 0
),
array(
'id' => 3,
'name' => 'Philosophy',
'post_count' => 0
)
);
I am using CakePHP 2.5, xampp.
Ah, the error was explicit. I was importing the table definition for the model automatically, but had the wrong list of fields in the records section.

Laravel 4, Ubuntu, SQL Server 2008R2

I'm using default PHP 5.3.10 in my ubuntu box. and install php5-sysbase.
I tested with this code and success connected to my SQL Server
<?php
$link = mssql_connect('125.0.0.1', 'sa', '12345');
if(!$link) {
echo'Could not connect';
die('Could not connect: ' . mssql_error());
}
echo'Successful connection';
mssql_close($link);
Now I'm following the quickstart tutorial until arrive at database things in http://laravel.com/docs/quick#creating-a-migration
I use default db driver sqlsrv, with this config:
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => '125.0.0.1',
'database' => 'laravel',
'username' => 'sa',
'password' => '12345',
'prefix' => '',
),
When I execute php artisan migrate, I got an error
[Exception]
SQLSTATE[HY000]: General error: 102 General SQL Server error: Check message
s from the SQL Server [102] (severity 15) [(null)] (SQL: create table "migr
ations" ("migration" nvarchar(255) not null, "batch" int not null)) (Bindin
gs: array (
))
What could be the problem? Thanks for any helps
EDIT01:
here's sql message:
message_id language_id severity is_event_logged text
102 1033 15 0 Incorrect syntax near '%.*ls'.
here's my migration file:
<?php
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('email')->unique();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('users');
}
}
/vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Change this:
protected $wrapper = '"%s"';
To this:
protected $wrapper = '[%s]';