ASP.NET MVC5 (Postgresql)で新規スキャフォールディング時にエラー

はじめに

Visual Studio 2019 のASP.NET MVC5で新規スキャフォールディング時に、以下のエラーが発生。
手がかりがあまりなくて混乱してしまいましたが、以下の対処によって解消しました。

選択されたコード ジェネレーターの実行中にエラーが発生しました: "value-1 は許容される [0, 2147483647] の範囲外です。パラメーター名: 値"

前提

Visual Studio 2019をアップデートする


Visual Studio 2019 バージョン 16.2 リリース ノート | Microsoft Docs
Visual Studio 2019をバージョン16.2.4以降にアップデートしてください。

(「ヘルプ」から「更新プログラムの確認」を選択します。)

Entity Data Modelウィザードで「データベースからCode First」時に
npgsql.typemapping.globaltypemapper のタイプ初期化子が例外をスローしました。
と表示されていましたが、こちらもアップデートで解決したもよう。

Visual Studio Code インストール+日本語化+文字コード変更

はじめに

(2019年12月)
Visual Studio Code をインストールして、日本語化するまでの手順です。
よくやる文字コードの変更手順もメモします。
慣れていなくて、忘れがちだったのでメモしました。
あとの細かい設定はお好みで

前提

  • Windows10

Visual Studio Code をダウンロードする

下記よりダウンロード

Download Visual Studio Code - Mac, Linux, Windows

f:id:wanouri:20191209212006p:plain

インストールする

f:id:wanouri:20191209212108p:plain
同意する

f:id:wanouri:20191209212209p:plain
インストール先の指定

f:id:wanouri:20191209212418p:plain
プログラムグループの指定

f:id:wanouri:20191210000855p:plain
追加タスクの選択

f:id:wanouri:20191210001036p:plain
インストール状況

f:id:wanouri:20191210001212p:plain
セットアップウィザード完了

日本語化する

f:id:wanouri:20191216192704p:plain
View - Command Pallet

f:id:wanouri:20191216192916p:plain
config と入力して、Configure Display Language を選択する


f:id:wanouri:20191216192833p:plain
Install additional languages

f:id:wanouri:20191216193536p:plain
日本語を選択します

f:id:wanouri:20191216193614p:plain
Install

f:id:wanouri:20191216193710p:plain
Restart now を押します

文字コードを変更する

f:id:wanouri:20200116110633p:plain
設定を開きます
f:id:wanouri:20200116110747p:plain
[テキストエディター]ー[ファイル]ー[Encoding]で文字コードを選択します

Raspberry PiでDjango+mariaDB

はじめに

Raspberry PiDjangoを動かしてみます。DBは、mariaDBで。

前提

djangoをインストールする

$ sudo pip3 install django 

プロジェクトを作成する

sampleというプロジェクトを作成することにしています。

$ django-admin.py startproject sample

アプリを作成する

sampleappというアプリを作成することにしています。

$ cd sample
$ django-admin.py startapp sampleapp

setting.pyを編集する

sample/sample/setting.pyを編集します。
ALLOWED_HOSTSは、外部アクセスさせたいので * を記述します。
DATABASESは、mariadbの定義に合わせて記述します。

ALLOWED_HOSTS = ['*']

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'hoge', # DB名
        'USER': 'user', # ユーザ名
        'HOST': 'localhost',
        'PASSWORD': 'password',
        'PORT': '3306',
    }
}

データベースを構築する

$ sudo python3 manage.py migrate

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

データベース管理者を設定する

$ sudo python3 manage.py createsuperuser
Username (leave blank to use 'root'): 
Email address:
Password:
Password (again):
Superuser created successfully.

起動する

$ sudo python3 manage.py runserver 0.0.0.0:8000

確認する

ブラウザで、URLを入力します。(http://xxx.xxx.xxx.xxx:8000
f:id:wanouri:20191128174247p:plain

Raspberry Piにインストールしたmariadbに別の端末から接続できない

はじめに

Raspberry Piにインストールしたmariadbに別の端末から接続しようとすると、以下のメッセージが表示され接続できない。

Can't connect to MySQL server on 'xxx.xxx.xxx.xxx'

前提

50-server.cnf を編集する

sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf 

bind-address = 127.0.0.1コメントアウト

# bind-address = 127.0.0.1 

mariadbを再起動する

$ sudo systemctl restart mysql

確認する

別の端末から接続を行い確認します。

Raspberry Piで固定ip

はじめに

RaspberryPiで固定ipを設定します。

前提

interfaces を編集する

sudo vim /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual

dhcp.confを編集する

sudo vim /etc/dhcpcd.conf

interface wlan0
static ip_address=192.168.1.10/24
static routers=(ゲートウェイのアドレス)
static domain_name_servers=(DNSのアドレス)

再起動する

sudo reboot

確認する

ifconfig コマンドで、ipが取得できていることを確認します。

Raspberry PiでWifi接続

はじめに

RaspberryPiでWPA-PSKのWifiに接続します。

前提

wpa_supplicant.confを編集する

sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
   ssid="(SSID)"
   psk=パスワード
   key_mgmt=WPA-PSK
   proto=RSN
   pairwise=CCMP
   priority=2
   scan_ssid=1
}

interfaces を編集する

sudo vim /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp


再起動する

sudo reboot

確認する

ifconfig コマンドで、ipが取得できていることを確認します。

docker上にRedmineを構築する

はじめに

docker上にRedmineを構築して運用できるようにします。

前提

以下の記事を参考にして、dockerをインストールします。
wanouri.hatenablog.com

docker-composeコマンドをインストールする

以下のコマンドを実行して、docker-composeコマンドをインストールします。

curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Redmineのdockerファイルをダウンロードする
Redmineのバージョン3.4を利用します。

mkdir -p /opt/www/redmine
cd /opt/www/redmine
git clone -b 3.4-stable  https://github.com/sameersbn/docker-redmine.git

docker-composeを起動して確認する

cd /opt/www/redmine/docker-redmine
docker-compose up

以下、表示できれば起動

INFO success: unicorn entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
INFO success: cron entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

ブラウザで確認します。(http://hogehoge.com:10083

f:id:wanouri:20191002145554p:plain
redmineトップ画面

ログイン

ユーザ名 パスワード
admin admin

デーモンで起動する

docker-compose up -d

停止する場合

docker-compose stop