【问题标题】:An exception occured in driver: SQLSTATE[HY000] [14] unable to open database file驱动发生异常:SQLSTATE[HY000] [14] 无法打开数据库文件
【发布时间】:2018-01-15 16:09:42
【问题描述】:

当我想用 wamp server 创建一个新数据库时出现这个错误。我该如何解决

$ 应用程序/控制台原则:数据库:创建无法创建数据库 名为 default 的连接的“symfony”驱动程序中发生异常: SQLSTATE[HY000] [14] 无法打开数据库文件

parameters.yml:
    database_driver: pdo_sqlite
    database_host: 127.0.0.1
    database_port: null
    database_name: symfony
    database_user: root
    database_password: null
    database_path: '%kernel.root_dir%/data/blog.sqlite'
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: en
    secret: secret_value_for_symfony_demo_application

parameters.yml.dist:

 # This file defines the canonical configuration parameters of the application.
    # Symfony uses this file as a template to generate the real app/config/parameters.yml
    # used by the application.
    # See 

http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters
    parameters:
        # this demo application uses an embedded SQLite database to simplify setup.
        # in a real Symfony application you probably will use a MySQL or PostgreSQL database
    database_driver:   pdo_sqlite
    database_host:     127.0.0.1
    database_port:     ~
    database_name:     symfony
    database_user:     root
    database_password: ~
    # the 'database_path' is only used for SQLite type databases
    database_path:     %kernel.root_dir%/data/blog.sqlite

    # Uncomment these lines to use a MySQL database instead of SQLite:
    #
    # database_driver: pdo_mysql
    # database_host: 127.0.0.1
    # database_port: null
    # database_name: symfony_demo
    # database_user: root
    # database_password: null
    #




 # You can even create the database and load the sample data from the command line:
#
# $ cd your-symfony-project/
# $ php app/console doctrine:database:create
# $ php app/console doctrine:schema:create
# $ php app/console doctrine:fixtures:load





# If you don't use a real mail server, you can send emails via your Gmail account.
    # see http://symfony.com/doc/current/cookbook/email/gmail.html
mailer_transport:  smtp
mailer_host:       127.0.0.1
mailer_user:       ~
mailer_password:   ~

# The code of the default language used by the application ('en' = English)
locale: en

# The 'secret' value is a random string of characters, numbers and symbols
# used internally by Symfony in several places (CSRF tokens, URI signing,
# 'Remember Me' functionality, etc.)
# see: http://symfony.com/doc/current/reference/configuration/framework.html#secret
secret: 'secret_value_for_symfony_demo_application'

【问题讨论】:

    标签: mysql angularjs api symfony


    【解决方案1】:

    出现此消息的一个原因是用户无法在%kernel.root_dir%/data/ 文件夹中创建文件。检查您是否可以在此文件夹中创建文件。

    【讨论】:

    • 我在哪里找到这个文件夹?
    • "kernel.root_dir" 解析为包含 AppKernel 类的目录(通常是“app”)。因此,您正在寻找目录 ./app/data。确保它存在并且您的网络应用有权在其中写入。
    • 这里是关于可用内核参数的更多信息:stackoverflow.com/questions/31339120/…
    • @Gildas 在目录 ./app/data 我没有名为 data 的文件夹我现在可以做什么?
    • 您可能想创建这个文件夹?
    【解决方案2】:

    我在 config.yml @Markus 中有这个

     doctrine:
            dbal:
                # instead of configuring the database access options in this file, we pull
                # them from the app/config/parameters.yml file. The reason is that config.yml
                # stores options that change the application behavior and parameters.yml
                # stores options that change from one server to another
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                # if using pdo_sqlite as your database driver, add the path in parameters.yml
                # e.g. database_path: "%kernel.root_dir%/data/data.db3"
    
    
    
    
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
    

    【讨论】:

    • 你确定吗?如果您使用 sqlite,则不需要启用 database_path。尝试删除database_path#
    猜你喜欢
    • 2018-07-23
    • 2016-06-27
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 2021-11-19
    • 2020-08-07
    • 1970-01-01
    • 2015-03-15
    相关资源
    最近更新 更多