#Field 'name' doesn't have a default value (errno 1364)

74 messages · Page 1 of 1 (latest)

viral tartan
#

Hi, i'm getting an error when running python manage.py migrate. Here is the full error:

MySQLdb.IntegrityError: (1364, 'target: myapp.-.primary: vttablet: rpc error: code = Unknown desc = Field \'name\' doesn\'t have a default value (errno 1364) (sqlstate HY000) (CallerID: ktqd6qz126ncpf0wale9): Sql: "insert into django_content_type(app_label, model) values (:vtg1, :vtg2)", BindVars: {REDACTED}')

My model:

class CustomUser(models.Model):
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=50)
    subdomain = models.CharField(max_length=50)

    def __str__(self):
        return self.username
stark pulsar
viral tartan
#

@stark pulsar it's my User model and no i'm not changing it, I just switched to using mysql so I need to run the migrate command but i'm getting the error I said above

stark pulsar
#

That doesn't look like an reasonable code for a user model

viral tartan
#

Yeah but i'm using mysql with django for the first time, i'm trying to learn how to use it with mysql

stark pulsar
#

Well, anyway it seems that you are trying to write an empty value to db, so check what are you running

stark pulsar
#

Especially 50-long password field is ALARMING

viral tartan
stark pulsar
#

Even if it works, it may work in way it must not ever work

#

Or, are you really sure it works?

viral tartan
#

yeah i am

viral tartan
stark pulsar
#

It's just that your model worries me that you are not doing auth correctly

#

Do you have a full traceback of an error?

viral tartan
#
django.db.utils.IntegrityError: (1364, 'target: lunchautomate.-.primary: vttablet: rpc error: code = Unknown desc = Field \'name\' doesn\'t have a default value (errno 1364) (sqlstate HY000) (CallerID: ktqd6qz126ncpf0wale9): Sql: "insert into django_content_type(app_label, model) values (:vtg1, :vtg2)", BindVars: {REDACTED}')

This is the other part

stark pulsar
#

And nothing above it?

#

It happens on migrate ?

viral tartan
#

yes

stark pulsar
#

What is full console output right after command?

#

If it doesn't go to "Applying migrations" (or smth like that) - you have bigger problems with your code

viral tartan
#

It does go to applying migrations, i'm unable to send a screenshot here for some reason

stark pulsar
#

We don't like screenshots, please copy text

viral tartan
#

Alright

#

This is the output of show tables; in the mysql cli:

lunchautomate/main> show tables;
+----------------------------+
| Tables_in_lunchautomate    |
+----------------------------+
| auth_group                 |
| auth_group_permissions     |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_content_type        |
| django_migrations          |
+----------------------------+
#

Not sure if it helps you

#

Isn't there supposed to be some CustomUser table?

stark pulsar
#

Well it only shows that migrations did run to some point

#

but again, I'd like to see output of migrate command from start to the end

viral tartan
#

And this is the output of the migrate command:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, django_cron, sessions
Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/django/db/backends/mysql/base.py", line 75, in execute
    return self.cursor.execute(query, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
          ^^^^^^^^^^^^^^^^^^
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
MySQLdb.IntegrityError: (1364, 'target: lunchautomate.-.primary: vttablet: rpc error: code = Unknown desc = Field \'name\' doesn\'t have a default value (errno 1364) (sqlstate HY000) (CallerID: ktqd6qz126ncpf0wale9): Sql: "insert into django_content_type(app_label, model) values (:vtg1, :vtg2)", BindVars: {REDACTED}')

The above exception was the direct cause of the following exception:
#

the end I didnt send because of discord characters limit

stark pulsar
#

Yeah, this one is more useful

#

well, there are no migrations for you model it seems

viral tartan
#

Also do I understand it correctly that to use mysql with django I need to install mysqlclient with pip and mysql package with my systems package manager?

stark pulsar
#

You need a mysql server running and at least a python client lib. Can't tell any more mysql is not very popular with django

stark pulsar
viral tartan
#

Hmm I see, i'm trying to use mysql because I'm using planetscale

viral tartan
stark pulsar
#

Then I can guess it happens in post-migrate signal,though I don't have proofs

viral tartan
#

I could try deleting all tables in my db and rerun the migrate command

stark pulsar
#

Looks like error may come from MySQL configuration

#

Are you sure your version is compattible with django or python client?

viral tartan
#

how can I know what mysql version I'm running?

viral tartan
#

so I had to change the charset of django sql client to utf8mb4

stark pulsar
#

check your package manager

stark pulsar
viral tartan
#

It says this: mysql Ver 15.1 Distrib 10.11.2-MariaDB, for Linux (x86_64)

#

oh I don't even have mysql itself installed, but instead mariadb

#

these three:

Packages (3) mariadb-clients-10.11.3-1  mariadb-libs-10.11.3-1
             mariadb-10.11.3-1
stark pulsar
#

mariadb is not mysql

#

Looks like it's a supported version of maria though

viral tartan
#

I don't even know how I have installed mysql wait a sec

#

Yeah i have installed mariadb 10.11.2-2

stark pulsar
#

I don't see any specific notes for maria in docs

#

So ifyou have django >= 3.0 it should work

#

not sure about python client

viral tartan
#

for the python client I have mysqlclient 2.1.1

#

now it's giving me a different error after I had deleted all tables and rerun the migrate command:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, django_cron, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial...Traceback (most recent call last):
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/django/db/backends/mysql/base.py", line 75, in execute
    return self.cursor.execute(query, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
          ^^^^^^^^^^^^^^^^^^
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/home/michal/Desktop/files/coding/python/lunchautomate/venv/lib/python3.11/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
MySQLdb.OperationalError: (1105, 'foreign key constraints are not allowed, see https://vitess.io/blog/2021-06-15-online-ddl-why-no-fk/')
hexed knot
#

Your Custom user doesn't have a field like "name". Do you really have this field somewhere? may be on another model?

viral tartan
#

I don't think so, I only have one models.py file

stark pulsar
hexed knot
viral tartan
#

I have no content_type table that I'm aware of

#

I probably need to use their database wrapper

stark pulsar
hexed knot
viral tartan
#

I think the problem is that planetscale doesn't support foreign key constraints

#

I will switch to postgres then

hexed knot