douhaoqiao9304 2014-12-07 13:53
浏览 118
已采纳

SQLite不支持drop; 什么用于Laravel单元测试

So it seems SQLite does not support dropping column. I have dropped/re-added columns over the time I build my application. I changed my database to. So right now, in my migration folder, there are folders that use $table->dropColumn('someColumn'). When I use SQLite, I get an error on that line (which was explained in the link above).

This tells me that I cannot use SQLite. So I decided to use MySQL:

<?php

return [

    'fetch' => PDO::FETCH_CLASS,

    'default' => 'mysql',

    'connections' => [
        'mysql' => [
            'driver'   => 'mysql',
            'database' => ':memory:',
            'prefix'   => '',
        ]
    ]

];

But I get an error: PDOException: SQLSTATE[HY000] [2002] No such file or directory

What connection should I then use for my unit testing?

  • 写回答

1条回答 默认 最新

  • doujing2017 2014-12-07 14:14
    关注

    MySQL doesn't have an in-memory feature like SQLite, so 'database' => ':memory:' won't work (short of starting a mysql server instance to write specifically in memory). Just setup a test database configuration in app/config/testing/database.php:

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'test_database',
        'username'  => '*******',
        'password'  => '*******',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    )
    

    And run the migrations on setUp and reset the migrations on tearDown.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部