Cant create migration phinx - php

When I try create migration I get this exception, but I have not got curly braces in my migration path
[Exception]
You probably used curly braces to define the migration path in your Phinx configuration file, but no directories have been matched using this pattern. You need to create a migration directory manually.
My config:
paths:
migrations: %%PHINX_CONFIG_DIR%%/db/migrations
seeds: %%PHINX_CONFIG_DIR%%/db/seeds
environments:
default_migration_table: phinxlog
default_database: development
production:
adapter: mysql
host: localhost
name: production_db
user: root
pass: ''
port: 3306
charset: utf8
development:
adapter: mysql
host: localhost
name: development_db
user: root
pass: ''
port: 3306
charset: utf8
testing:
adapter: mysql
host: localhost
name: testing_db
user: root
pass: ''
port: 3306
charset: utf8
version_order: creation

Just came across this same error when trying to setup CakePHP & Phinx.
Was caused by missing out the directory when running the Phinx command.
Docs say to init the system type :
phinx init .
(If Phinx was installed via composer use : vendor/bin/phinx init . )
If you miss out the '.' you get the error you have described. It looks like Phinx doesn't have a default setting of using the currently working directory.
http://docs.phinx.org/en/latest/commands.html#the-init-command.
You can fix the issue by ether re-running the Phinx command or by manually creating the folders :
mkdir -p db/migrations db/seeds
Hope this helps anyone searching in the future.

Not sure if you ever found your answer, but I fixed this error by manually creating the db/migrations directory in the root. You might have to do the same with db/seeds.

Probably you are running "php vendor/bin/phinx " from inside the migration directory. Try this from root directory. I was getting same error and fixed from root folder.

If you are using CakePHP 3.0 or 4.0 your paths might need updating..
'paths' => [
'migrations' => '%%PHINX_CONFIG_DIR%%/config/Migrations',
'seeds' => '%%PHINX_CONFIG_DIR%%/config/Seeds'
],
Worked for me.

Related

Doctrine insists on trying to use PostgreSQLDriver despite contrary config

I am setting up a Symfony 5.2 app, using doctrine/doctrine-bundle 2.4 and doctrine/orm 2.9. My doctrine.yaml config file looks like this:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
The problem is that when I run doctrine:fixtures:load, I get the following output:
In AbstractPostgreSQLDriver.php line 102:
An exception occurred in driver: could not find driver
In Exception.php line 18:
could not find driver
In PDOConnection.php line 39:
could not find driver
It looks like Doctrine is trying to use the Postgre driver, though I have specified MySQL. Is there another place where I need to configure this? If so, how?
===
EDIT: It looks like DATABASE_URL is not available inside my Docker container, which is probably the source of the problem. I've verified that DATABASE_URL is defined in my .env file, and that my .env file is in the same folder as my docker-compose.yml file. Also, I have a setting like this for the environment variable in that docker-compose file:
environment:
- DATABASE_URL
So I'm not quite sure what's wrong here.
I think you have a wrong DATABASE_URL in your .env file. Please check if it starts with mysql://.
I believe symfony uses dotenv package to load the values from .env to the S_ENV superglobal. You need to debug whether your dotenv (and there is a .env in your project and it is not .env.local or .env.dist) is loaded properly.
It has happened to me sometimes when I was starting, typically when cloning a Github project which has a default .env file created by Doctrine when it's installed through composer that by default Doctrine uses PostgreSQL URL.
See how many .env files have you document and I'm sure that someone overrides your URL connection.
See this StackOverflow post to know the difference between the .env.* files What is the difference between .env.local and .env.development.local

How to use mysql instead of mariadb in symfony 5

i think this might be a stupid question for some, but i swear that i can't find the answer by myself actually.
I'm still learning Symfony so please be nice.
Actually i have set up the access to my database in the .env file :
[...]
DATABASE_URL=mysql://root:db_password#127.0.0.1:3308/db_name
[...]
And then i have define the environnement variable in the config/doctrine.yaml :
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: Symfony
user: root
password: null
host: localhost
server_version: '8.0'
driver: pdo_mysql
charset: UTF8
So i run the following command :
> php bin/console doctrine:database:create
But the 'Symfony' database have been created under mariadb.
:( I don't understand why because i have define precisely that i use a 8.0 version and this version is not a mariadb version.
I've also try this :
# .symfony/services.yaml
mydatabase:
# supported versions: 5.7, 8.0
type: oracle-mysql:8.0
disk: 1024
As the symfony documentation saying to do, but it still not working at all.
I have got the following error message as mydatabase is not a symfony services :
C:\Users\vincp\Symfony\charming_tuto>php bin/console doctrine:database:create
In FileLoader.php line 173:
There is no extension able to load the configuration for "mydatabase" (in "C:\Users\vincp\Symfony\charming_tuto\con
fig/services.yaml"). Looked for namespace "mydatabase", found ""framework", "sensio_framework_extra", "twig", "twig
_extra", "web_profiler", "monolog", "debug", "webpack_encore", "doctrine", "doctrine_migrations", "maker"" in C:\Us
ers\vincp\Symfony\charming_tuto\config/services.yaml (which is being imported from "C:\Users\vincp\Symfony\charming
_tuto\src\Kernel.php").
I wanna use mysql because this is the DBMS that i use usually.
(If you think that i should use mariadb instead of mysql i'm open to that, but give me some arguments. I'd be really interseted in)
Maybe it is a server issue. So first, make sure that MySQL is running on your server besides MariaDB (how to do it depends on the type of server you are using).
If yes, it might be a port setting issue: I see that you set the database port to 3308. That is probably the port on which MariaDB is listenning. Try to determine if there is another db running on your server listening to another port (for example 3306 is very often the default MySQL port). To do so, on a Linux server you could try the following command :
netstat -tlnp | grep mysql
If you find only x x.x.x.x:3308 address or so, I bet that MySQL is not running on your server and you only run a MariaDB instance. But if you find addresses on other ports (for example x x.x.x.x:3306) chances are that a MySQL instance is running and listens that other port. If that's the case, you should consequently change the DATABASE_URL in your .env file.

Laravel deployment using Google App Engine: No such file or directory

I have followed this tutorial and created a database under the name zoho_portal. My app.yaml contents are:
runtime: php
env: flex
runtime_config:
document_root: public
# required on some platforms so ".env" is not skipped
skip_files: false
env_variables:
# The values here will override those in ".env". This is useful for
# production-specific configuration. However, feel free to set these
# values in ".env" instead if you prefer.
APP_LOG: errorlog
STORAGE_DIR: /tmp
CACHE_DRIVER: database
SESSION_DRIVER: database
## Set these environment variables according to your CloudSQL configuration.
DB_HOST: localhost
DB_DATABASE: zoho_portal
DB_USERNAME: USER
DB_PASSWORD: PASS
DB_SOCKET: /cloudsql/zoho-portal-159018:us-central1:zoho-portal
beta_settings:
cloud_sql_instances: "zoho-portal-159018:us-central1:zoho-portal"
I have also added this to my composer.json:
"post-deploy-cmd": [
"chmod -R 755 bootstrap\/cache"
]
However, after deploying this using gcloud app deploy, and visiting the website at: https://zoho-portal-159018.appspot.com/, I receive this error:
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from
sessions where id = iq8isoeEqTaj5xVNmVm0JuFKtR8vtSEB0ajJl23o limit
1)
As far as I can see, I haven't missed any of the steps listed in the tutorial and the database is set up correctly. I also don't think it has anything to do with database migration. From what I can tell, this is an issue with how the socket file is set up.
The issue is with using database as the session driver. The temporary solution is to use another driver (memcached, redis) etc

Php - phinx migration

I am using phinx for migrations in my web app.
my phinx.yml:
paths:
migrations: %%PHINX_CONFIG_DIR%%/migrations
environments:
default_migration_table: app_migrations
default_database: app_database
development:
adapter: mysql
host: localhost:8888
name: app_database
user: ''
pass: ''
port:8889
I have mamp with ports apache:8888 and mysql:8889 running.
The database app_database does exist.
The table app_migrations does not exist(it will be created while migrating right?)
I already created some migrations and now i try to run them:
php vendor/bin/phinx migrate -e development
output in console:
Phinx by Rob Morgan - https://phinx.org. version 0.5.1
using config file ./phinx.yml
using config parser yaml
using migration path /path/to/directory/migrations
using environment development
using adapter mysql
using database app_database
Then it stops and nothing happens...
Anybody could help me with this issue?
Thanskj and Greetings!
Maybe there is some config-hickup. I know this phenomenon from conneting to a mysql-database that is not reachable via a specific host / port. This always leads to timeouts but only after eg. 60 seconds.
You wrote this in your config:
host: localhost:8888
[...]
port: 8889
First remove the port from the hostname:
host: localhost
port: 8889
and as second verify the mysql-server is really listening on localhost / port 8889.
You'll find more on in the "Configuration"-chapter of phinx-documentation: http://docs.phinx.org/en/latest/configuration.html
Regards
If you're using the default settings for MAMP, the username for the database would be root. Try changing the value of user in phinx.yml to root.

Codeception - pointing DB to MAMP MySQL server

Is there a way to point the DB module for Functional tests in codeception to your MAMP MySQL server rather than the built in server?
class_name: TestGuy
modules:
enabled: [Db, Filesystem, TestHelper]
config:
Db:
dsn: 'mysql:host=localhost;dbname=testdb'
user: 'root'
password: 'root'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: false
Codeception uses PDO to connect to the database. It will pass the "dsn" string straight into the PDO constructor. Thus, according to http://www.php.net//manual/en/ref.pdo-mysql.connection.php, your configuration should be the following in order to connect to the MAMP MySQL Server running on port 8889:
class_name: TestGuy
modules:
enabled: [Db, Filesystem, TestHelper]
config:
Db:
dsn: 'mysql:host=localhost;port=8889;dbname=testdb'
user: 'root'
password: 'root'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: false
This is what fixed the issue for me.
In MAMP I ticket the box "Allow network access to MySQL"
My dsn setting in codeception.yml is:
dsn: 'mysql:host=127.0.0.1;port=3306;dbname=la51'
Have you tried this at all - might work for you too..
class_name: TestGuy
modules:
enabled: [Filesystem, TestHelper, WebHelper, PhpBrowser]
config:
PhpBrowser:
url: 'http://localhost/yourapp/'
curl:
CURL_RETURNTRANSFER: true
Let me know how that works for you :)
http://codeception.com/docs/modules/PhpBrowser
I'd double check your mysql table within the dump
Once setup just add something like this to your tests
$I->seeInDatabase('users', array('name' => 'Davert', 'email' => 'davert#mail.com'));
Thiss will check the 'users' table and look for the row with the name & email as supplied in the array - works for me.
Two things—I believe—would fix this your problem
Make sure the module for which you are setting the database parameters is the same. DB is different from Db
MAMP runs its MySQL on port 8889. If you only specify localhost in the dsn string, Codeception will try to connect to a MySQL instance running on port 3306—which is MySQL's default port. Change localhost to localhost:8889
I just fixed this problem myself. Comment for further clarifications if need be.
Cheers
EDIT
Recently, I revisited the project which I used Codeception. This solution did not work for me. I ran into two issues
Timezone Exception You can fix this by...
Making sure the timezone is set correctly in your php.ini file, which is usually in /Applications/MAMP/bin/php/php5.x/conf/
AND/OR aliasing php to use MAMP's by doing alias phpm="/Applications/MAMP/bin/php5.x/bin/php"
[Codeception\Exception\Module] (Exception in Db) This is primarily because of the configuration of the module. I removed the port number from my configuration and everything seems to work fine.

Categories