Preventing Doctrine from Dropping / Recreating Database When using build --all - php

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.

Related

MySQL - Moving from 5.7 to 8 issue with altering 'function' to 'job_title'

In the past I have been using MySQL 5.7 for a Symfony project.
I have the table 'work_experience' with a column named 'function' this causes an obvious syntax error because 'function' is a restricted word. This has started since moving to MySQL 8. Now I am trying to alter this column name from 'function' to 'job_title' this is also failing because of the same syntax error. How can I bypass this to solve my issue? This all worked fine on my local machine because I am using MariaDB 10.4 in a Docker container, but now it's failing on production.
I am using doctrine:schema:update because the schema is now several migrations behind because of this bug.
The error:
bin/console d:s:u --force
Updating database schema...
[error] Error thrown while running command "'d:s:u' --force". Message: "An exception occurred while executing 'ALTER TABLE work_experience CHANGE function job_title VARCHAR(255) NOT NULL':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'function job_title VARCHAR(255) NOT NULL' at line 1"
Doctrine schema validate:
bin/console d:s:v
Mapping
-------
[OK] The mapping files are correct.
Database
--------
[ERROR] The database schema is not in sync with the current mapping file.
Would dumping and recreating the schema/database work? I have this all setup using Doctrine migrations but I can run manual queries on the production server.
Dumping the database would cause a lot of manual work to recreate some of the data that is critical for the site to function.

"Syntax error or access violation: 1142" in Symfony and MySQL

I am creating an API REST aplication with Symfony3, and I have this problem. When I execute the methods in localhost it works fine, but I have uploaded the project to a server administered with Plesk, and when I try to execute the methods with postman, it shows this:
An exception occurred while executing 'SELECT t0.random_id AS ...'
with params [\"a\", \"a\"]:\n\nSQLSTATE[42000]: Syntax error or access
violation: 1142 SELECT command denied to user 'app'#'localhost' for
table 'table_name'
It seems to be a permissions problem, but if I try to access to the database with MysQL Workbech, with the same credentials, I can do it and execute querys without problems. And in the Plesk panel, the user has all the permissions and privileges.
I have also tried changing "localhost" for the host address in the parameters file of Symfony.
Looks like app user doesn't have permissions to execute SELECT query.
Run following MySQL query to fix it:
GRANT SELECT on database_name.* to 'app'#'localhost' identified by 'your-pass';
FLUSH PRIVILEGES;

Laravel 5.4 - I can't even execute php artisan config:clear - [Illuminate\Database\QueryException] SQLSTATE[HY000] [1044]

My project was working fine. After copy and pasting files in another Mac localhost, I always get the same error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1044] Access denied for user ''#'localhost' to database '***' (SQL: select * from roles)
[PDOException]
SQLSTATE[HY000] [1044] Access denied for user ''#'localhost' to database '***'
I already checked the .env file, but it seems Laravel can't execute code at this point. This 'roles' is a table with many to many relations trough pivot table.
Note 1: Fresh Laravel aplications works fine.
Note 2: Because I can't clear the cache, Laravel always considers the user to b be blank.
Can someone help me, please?
Thank you!
If your connection string is cached it will continue to use that.
You can try clearing and rebuilding the connection and config strings with
php artisan config:cache
or you can clear explicitly with:
php artisan cache:clear
It that that does not work I think your database is not connecting for other reasons.
Are you using MySQL or SQL Server?
I replaced files off a fresh application with my files(models, controllers, middlewares, migrations ...) and everything worked fine.
The solution:
https://laracasts.com/discuss/channels/general-discussion/base-table-or-view-not-found-1146-table-doesnt-exist/replies/151761

Laravel migrations completed but not always visible in database

I am working with a team on a project in laravel and have to migrate the database with vagrant ssh using scotchbox. Using the php artisan migrate method in /var/www I can migrate the set up migrations. These will get migrated successfully.
When I log in using Sequel Pro or MySQLWorkbench, these tables appear in the database. But then they disappear, being invisible most of the time even whilst keeping the connection. Resetting, refreshing or tinkering with the migrations does not seem to fix the problem. I tried to add some records but upon loging in with my user it does not work, receiving this error:
QueryException in Connection.php line 651:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'scotchbox.users' doesn't exist (SQL: select * from users where email = jos#jos.com limit 1)"
My tables can not be found even though they are migrated. Oddly, and I am not sure if it has anything to do with it, I sometimes get a "FORBIDDEN: you don't have permission to acces /page on this server" when being on any page. But nevertheless, I have a migration problem. Thanks in advance for helping me.
The issue was multiple VM's on the same IP. Resulting in the signal flaking and the database not always being found. The connection was there but not always the right one.

Cannot create postgres database with Doctrine

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.

Categories