I have project in Symfony2 with doctrine. In one moment i loose ability to create/drop databases via console commands like
app/console doctrine:database:drop --force
app/console doctrine:database:create
app/console doctrine:schema:update --force
If i attemp to create database, doctrine give me next error:
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[08006] [7] FATAL: database "motherhood" does not exist
So, i can create database in psql with user, written in symfony config. If i try to drop existing database via Doctrine, it gives me this:
SQLSTATE[55006]: Object in use: 7 ERROR: database "motherhood" is being accessed by other users
DETAIL: There are 1 other session using the database.
But there is no connection to this database
The quick fix for the problem is to create a database with the same name as user executing the command, because PostgreSQL must connect to a database, even when creating a new one.
The failure when dropping the database should be fixed in DoctrineBundle 1.4.
The failure to create the database will be fixed in doctrine/dbal in the very next release (2.5.2) as mentioned here: https://github.com/doctrine/DoctrineBundle/issues/402 . The problem will be fixed by always connection to the template database, which cannot be dropped.
Related
I have a Symfony 3.4 application connected to an Oracle DB via a Wallet, so the configuration of the DB username and password are outside the app and of my control.
To let the application to work with this specific configuration I added in the config.yml, the parameter:
doctrine:
dbal:
connections:
default:
...
session_mode: !php/const OCI_CRED_EXT
...
The application works without any problem.
I have a sync function that connect to different DBs and sync some data.
The sync function can be run manually within the application UI and it works.
I wrote a console command to run in a cron job that instantiate the same set of classes used manually by the application but I got the error in object when I execute the command via terminal.
The exact error is:
In AbstractOracleDriver.php line 57:
An exception occurred in driver: ORA-12154: TNS:could not resolve the connect identifier specified
In OCI8Exception.php line 16:
ORA-12154: TNS:could not resolve the connect identifier specified
The same error occurs when testing the db connection with the console:
#php .\bin\console doctrine:query:sql "select sysdate,current_date from dual"
So, it seams that the console command in some way ignore that the oracle connection i made through a wallet and looks for servicename parameter which is, obviously, empty resulting in a TNS error.
Do someone have some suggestion on how to fix the issue?
Thanks,
Marco
I'm trying to setup already made project but I'm stuck at the migrating the DB. I'm using Laravel (5.6.34) on PHP 7.2.9, and MySQL (8.0.12). If I try to run php artisan migrate command I'm getting no output, command stays "active" but nothing happens, no errors.
I tried making fresh project, adding migration and running the same command, same thing. I noticed that all other (or at least bunch of them I tried) artisan commands are working but only migrate one doesn't.
.env info is correct and mysql is up and running.
Any help is appreciated.
Thank you!
Try the following;
1. Check your migration files for content.
2. Flush config with php artisan config:clear
3. Check if database is connected using tinker. Run php artisan tinker then paste in this code; DB::connection()->getPdo();
4. If PDO object is returned, your app is connected to the database. If not and PDOException with message 'SQLSTATE[HY000] [2002] Connection refused' is returned then mysql is not running. If database does not exist, you get the error PDOException with message 'SQLSTATE[HY000] [1049] Unknown database [your_db].
Assigning the password to DB User solved this issue for me (be sure populate DB_PASSWORD inside .env)
mysqladmin -u YOURDBUSER password 'newpassword'
In my project I want to create console commands for dropping and creating DB, just like in Symfony2 like database creation command in laravel console? The way described in the answer to that question works fine for dropping DB, but when I try to create it with this code:
$dbType = \Config::get('database.default');
$dbName = \Config::get('database.connections')[$dbType]['database'];
\DB::statement("CREATE DATABASE `$dbName`");
I get an exception: SQLSTATE[42000] [1049] Unknown database 'my_awesome_db_name'. Any ideas?
Laravel is trying to connect to MySQL and select the database my_awesome_db_name. This isn't possible, because that database name doesn't exist yet (you haven't created it), so MySQL fails on the internal USE my_awesome_db_name command.
I have a problem with an SQLite3 database where I can access it either with the sqlite3 command or with the PHPStorm built-in database manager but the application I am working on doesn't find the tables in it. It correctly connects to the database it seems.
This line of PHP causes the PDOException:
$query = "SELECT * FROM users";
$results = self::$app->db->query($query);
And the exception is simply SQLSTATE[HY000]: General error: 1 no such table: users. I am using the Slim framework, by the way.
I don't really know what to do as I am new to Slim as well as SQLite.
Thank you for your help :-)
The database that you have opened does not contain this table.
SQLite will happily open any file name; if it does not exist, it will create a new, empty database.
Check your database file name.
Thanks to the accepted answer that pointed me in the right direction.
I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :
# file: PROJECT_ROOT/.env
DATABASE_URL="sqlite:///../my_super.db"
But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:
PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql
The problem:
I have a database that's running on a shared server.
I do not have permission to drop/ create a database via the command line
doctrine SQLSTATE[42000]: Syntax error or access violation: 1044 Access denied for user 'opnsrce'#'173.236.128.0/255.255.128.0' to database 'dev'. Failing Query: "DROP DATABASE dev"
doctrine Creating "all" environment "doctrine" database
doctrine SQLSTATE[42000]: Syntax error or access violation: 1044 Access denied for user 'opnsrce'#'173.236.128.0/255.255.128.0' to database 'dev'. Failing Query: "CREATE DATABASE dev"
This error occurs when I run
/dh/cgi-system/php5.cgi symfony
doctrine:build --all
--no-confirmation
The Question: How do I run build-all while simultaneously telling doctrine to not drop / create the database (it already exists)?
Update 1:
What further information can I provide in order to help the SO community answer this question?
If you just want all the classes to be rebuilt but the db not to be dropped and recreated, try running:
symfony doctrine:build --all-classes
The build task has a lot of different options and flags. Try running:
symfony help doctrine:build
to see all of your options.