I use MAMP server with PHP 7.1.5; Symfony Framework 3.4.2, PostgreSQL 10 for a new project. I also use PostGIS to store space data with geometry data type in PostgreSQL. Therefore I installed and used: "jsor/doctrine-postgis": "^1.5"
Following is part of my composer.json:
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"jsor/doctrine-postgis": "^1.5",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0"
The parameters.yml:
server_ver: 10.0
database_driver: pdo_pgsql
database_host: localhost
database_port: 5432
database_name: qtqg
database_path: ~
database_user: postgres
database_password: admin
The config.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
mapping_types:
_text: string
server_version: %server_ver%
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
path: %database_path%
user: %database_user%
password: %database_password%
persistent: true
charset: UTF8
logging: %kernel.debug%
profiling: %kernel.debug%
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
types:
geography:
class: 'Jsor\Doctrine\PostGIS\Types\GeographyType'
commented: false
geometry:
class: 'Jsor\Doctrine\PostGIS\Types\GeometryType'
commented: false
raster:
class: 'Jsor\Doctrine\PostGIS\Types\RasterType'
commented: false
Everything work well, I can use cmd to generate Entity:
php bin/console doctrine:mapping:import --force AppBundle annotation
And after that generate CRUD:
php bin/console generate:doctrine:crud AppBundleMonitoringAdminBundle:coquan -n --format=annotation --with-write
The Running PHP is PHP 7.1.5 and I also checked php.ini file in C:\Windows and loaded php.ini in MAMP server. php -m command shows:
PDO
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
I don't think any problem with data driver because it can connect and generate Entities, CRUD....
But after generate CRUD and try to access the controller to list all item in one Entity, I got the Error:
An exception occurred in driver: could not find driver
One of the error line is:
AbstractPostgreSQLDriver->convertException('An exception occurred in driver: could not find driver', object(PDOException)) in vendor\doctrine\dbal\lib\Doctrine\DBAL\DBALException.php (line 176)
I tried many way including changing mamp to xamp, wamp server, all recommendation about how to config dbal... but the error is still there
Could anyone help me!
the problem is with PostgreSQL 10
Inside vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php line line 292 change
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
For
$version = floatval($this->_conn->getWrappedConnection()->getServerVersion());
if ($version >= 10) {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = \'public\' AND sequencename = '.$this->_conn->quote($sequenceName));
}
else
{
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
}
I was have the same issue with postgres 9.6.4 with WAMP on windows 10
phpinfo() would display pdo_pgsql as loaded, and it worked fine in another PHP application. php -m from the gitbash would not show pdo_pgsql
In the end, I had to edit the php.ini that was loaded and uncomment these 2 lines
extension=php_pdo_pgsql.dll
extension=php_pgsql.dll
restart apache and now it works!!!!
Related
I have been pulling my hair trying to figure out what's wrong with mlflow. Iam deploying mlflow v1.26 in google cloudRun . back end artitfactory is google storage and backend database is google cloudsql postgres v13 instance.
here is my entrypoint using pg8000 v1.21.3 (I tried latest version as well) and psycopg2-binary v2.9.3
set -e
export ARTIFACT_URL="gs://ei-cs-dev01-ein-sb-teambucket-chaai-01/mlflow/"
export DATABASE_URL="postgresql+pg8000://mlflow:change2022#10.238.139.37:5432/mlflowps" #"$(python3 /app/get_secret.py --project="${GCP_PROJECT}" --secret=mlflow_database_url)"
if [[ -z "${PORT}" ]]; then
export PORT=8080
fi
exec mlflow server -h 0.0.0.0 -w 4 -p ${PORT} --default-artifact-root ${ARTIFACT_URL} --backend-store-uri ${DATABASE_URL}
now when I open mlflow ui page I see this error happening:
(
BAD_REQUEST: (pg8000.dbapi.ProgrammingError) {'S': 'ERROR', 'V':
'ERROR', 'C': '42883', 'M': 'operator does not exist: integer =
character varying', 'H': 'No operator matches the given name and
argument types. You might need to add explicit type casts.', 'P':
'382', 'F': 'parse_oper.c', 'L': '731', 'R': 'op_error'} [SQL: SELECT
DISTINCT runs.run_uuid..
)
You should use psycopg2 instead, e.g.:
postgresql+psycopg2://<username>:<password>#/<dbname>?host=/cloudsql/<my-project>:<us-central1>:<dbinstance>
It works for me, with versions:
mlflow==1.26.1
psycopg2-binary==2.9.3
Got a nest.js/typeorm/postgres application that I have been developing for the last year. Been creating/adding/removing tables/columns but never used migrations.
Now comes time to deploy and whenever I run typeorm migration:generate, a migration file is created for the last colums that I added/removed from only 1 or 2 tables.
Is it possible to generate a migration for all existing entities that are already part of my db schema?
Basically, the up would create each table with FKs, indexes, constraints, etc and the down would drop all of that.
Note: I noticed this post. Is this the correct approach for my issue?
I solved this by doing the following:
dropping and recreating my database in postgres
ran npm run typeorm:reset
then npm run typeorm:migrate
then typeorm:run
scripts for reference
package.json
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"typeorm:sync": "npm run typeorm schema:sync",
"typeorm:drop": "npm run typeorm schema:drop",
"typeorm:reset": "npm run typeorm:drop && npm run typeorm:sync",
"typeorm:migrate": "env NODE_ENV=development npm run typeorm migration:generate -- -n",
"typeorm:create": "env NODE_ENV=development npm run typeorm migration:create -- -n",
"typeorm:run": "ts-node -r tsconfig-paths/register $(yarn bin typeorm) migration:run"
ormconfig.js
const config = {
type: 'postgres',
host: process.env.RDS_HOST,
port: Number(process.env.RDS_PORT),
username: process.env.RDS_USERNAME,
password: process.env.RDS_PASSWORD,
database: process.env.RDS_DB_NAME,
synchronize: process.env.NODE_ENV === 'production' ? false : true,
dropSchema: false,
logging: process.env.NODE_ENV === 'development' ? true : false,
entities: [`${__dirname}/src/**/**.entity{.ts,.js}`],
migrations: [`${__dirname}/src/migrations/**/*{.ts,.js}`],
cli: {
migrationsDir: 'src/migrations',
},
}
module.exports = config
Note:
in my typeORM scripts, I use tsconfig-paths/register because I have path aliases in my tsconfig.json file that I use in my *.entity.ts files.
I'm installing Bucardo to replicate my Postgres server (10.1) on openSUSE Leap 42.3, and I have successfully complied the executable of Bucardo. When I tried bucardo install and modified the parameter as:
host:<none>
port:5432
user:aSuperUser
database:bucardo
piddir:/tmp/bucardo (already created)
Bucardo says: Postgres version is 4.8. Bucardo requires 8.1 or higher. How could this happen? I installed postgres 10, not 4.8. I also verified the version by select version(); and, there is only one postgres installation on my machine.
It seems to be fixed in master. There is a thread in the bucardo-general mailing list, that explains that you can make by yourself a couple of changes in the bucardo script or apply the diff:
diff --git a/bucardo b/bucardo index e1816f1..8e433ef 100755
--- a/bucardo
+++ b/bucardo ## -8979,7 +8979,7 ## sub install {
}
}
- if ($res !~ /(\d+)\.(\d+)(\S+)/) {
+ if ($res !~ /(\d+)\.(\d+)/) {
print "-->Sorry, unable to connect to the database\n\n";
warn $delayed_warning;
exit 1 if $bcargs->{batch}; ## -8988,10 +8988,7 ## sub install {
## At this point, we assume a good connection
## Assign the version variables
- my ($maj,$min,$rev) = ($1,$2,$3);
- ## We need to be able to handle things such as 9.2devel
- $rev =~ s/^\.//;
- $rev =~ s/(\d+)\.\d+/$1/;
+ my ($maj,$min) = ($1,$2);
$QUIET or print "Postgres version is: $maj.$min\n";
The bucardo script is in /usr/local/bin/bucardo and does not have write permissions so you must change it.
I am using Dancer::Plugin::Database to connect with database from my dancer application. It works fine for single connection. When i tried for multiple connection i got error. How can i add multiple connection.
I added the following code in my config.yml file:
plugins:
Database:
connections:
one:
driver: 'mysql'
database: 'employeedetails'
host: 'localhost'
port: 3306
username: 'remya'
password: 'remy#'
connection_check_threshold: 10
dbi_params:
RaiseError: 1
AutoCommit: 1
on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" ]
log_queries: 1
two:
driver: 'mysql'
database: 'employeetree'
host: 'localhost'
port: 3306
username: 'remya'
password: 'remy#'
connection_check_threshold: 10
dbi_params:
RaiseError: 1
AutoCommit: 1
on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" ]
log_queries: 1
Then i tried to connect with database using the following code :
my $dbh=database('one');
my $sth=$dbh->prepare("select * from table_name where id=?");
$sth->execute(1);
I got compilation error, "Unable to parse Configuration file"
Please suggest a solution.
Thanks in advance
YAML requires consistent indentation for the keys of a hash. Remove four spaces from before "two:" and it should parse.
Update: I see there's been some editing of indentation; going back to the original question produces a parsing error in a different place and shows a mixture of tabs and spaces being used; try to consistently use only tabs or only spaces. You can test your file and find what line is producing the first error like so:
$ perl -we'use YAML::Syck; LoadFile "config.yml"'
Syck parser (line 19, column 16): syntax error at -e line 1, <> chunk 1.
Also make sure that your keys are all ending up in the right hash (the mixture of tabs and spaces seems to allow this coming out wrong but still parsing successfully) with:
perl -we'use YAML::Syck; use Data::Dumper; $Data::Dumper::Sortkeys=$Data::Dumper::Useqq=1; print Dumper LoadFile "config.yml"'
i ran into this errors while trying to modify pinax database model
i am using eclipse pydev
i have this error on the pydev
Exception Type: TemplateSyntaxError at /
Exception Value: Caught an exception while rendering: (1146, "Table 'test1.announcements_announcement' doesn't exist")
please how do i correct this
UPDATE: i asked this question and left unresolved some months back and you what ran into the bug again this week and typed the error message in google hit the page with the question and unanswered so i think i have to answer it and hope it help someone in the future have the same problem.
some the problem is that the sqlite path is out of place so django or this case pinax can not find it so to resolve that change the absolute path to sqlite like it
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
DATABASE_NAME = os.path.join(PROJECT_ROOT,'dev.db' ) # Or path to database file if using sqlite3.
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
i hope that help
chnge the sqlite3 path like this
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. DATABASE_NAME = os.path.join(PROJECT_ROOT,'dev.db' ) # Or path to database file if using sqlite3. DATABASE_USER = '' # Not used with sqlite3. DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
If your database model is missing a column, run
python manage.py syncdb
from the command line. This ensures that your models match the underlying database representation.