找回密码
 注册
查看: 693|回复: 4

一次python django项目数据同步异常操作,重置过程,并同步到数据库

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2025-7-18 17:17:02 | 显示全部楼层 |阅读模式
因调试过程中,发现有点问题,就把数据库表从其他客户端删除了,以为删除了就可以同步过去,没想到就是下面的结果。! G. [3 \4 U: i5 |; _
(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py check
& G' |- y  t. E5 q# BSystem check identified no issues (0 silenced).% c: ^: N- }( O9 N' y9 Q
2 ^# T- s/ b+ y4 R( P4 F
(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py makemigrations
& Q7 |( K" @" i' n$ D# V6 pNo changes detected
: _: p7 _8 E3 K  k
* H/ ], k1 p3 Q6 U! V2 N( C(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py makemigrations order
8 I$ U2 b8 Y" Y9 b/ ZNo changes detected in app 'order'
+ X1 d0 V$ R* {$ V' O5 w9 U' X- x" N) }# w4 N3 V% I
(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py migrate order
( e  J2 V& `; aOperations to perform:
) @$ q; y  O# L0 G* I; q  Apply all migrations: order8 j1 Y+ E% Y( U% |: `) {
Running migrations:2 t3 y9 M: [! ?
  No migrations to apply.
4 L8 x9 m% K6 l2 a4 B& m
6 e$ n" h" A) {  u同步不过去,怎么办?+ B7 }, R- W# A
看到有高手的同步经历,按照他的方法,去执行了下,好像问题解决了。
7 F) t( S. [3 G( d' R2 ~6 J% w% `2 {" `7 D: f* ^
(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py dbshell- m/ i1 P) \# j5 b3 i# x4 H1 M
Welcome to the MariaDB monitor.  Commands end with ; or \g.+ x/ `1 y. C8 L
Your MariaDB connection id is 1526 h2 h& n; D. I) }
Server version: 11.5.1-MariaDB mariadb.org binary distribution
+ D2 l8 |" y( }
5 J  d6 F8 r6 v1 |Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
# I& G. A/ t/ d; G
, R  v- s$ {# [Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.3 b* |6 j# e# u# g! c
1 A4 X" G0 j- c+ D5 u  S" A4 R& e8 A
MariaDB [tripsql]> show tables;) ]- }) f- m' j
+-------------------------------+- z% s9 o; \# L2 G* P
| Tables_in_tripsql             |- [0 Z8 I) l+ d. Z/ T9 o! _9 G
+-------------------------------+
) `3 q" `2 a0 F$ S: M! X# L; ]| account_user                  |9 a( K1 e- T2 Z
| account_user_groups           |0 |  r& }" @$ d8 r
| account_user_user_permissions |
" ]% e6 Y- D1 e! b- f! V| accounts_login_record         |6 A& ?& U9 g9 j/ n& m% f4 K0 b$ q
| accounts_user_profile         |" V; Q  m& S2 I) r, x1 a
| auth_group                    |
7 u" q. r$ |* || auth_group_permissions        |
4 ]! U! [1 G0 Q; I7 N3 W| auth_permission               |
: a  [, n4 a, z( A! v4 l" T| auth_user                     |
: D1 x5 j8 v4 Q8 f* c  K| auth_user_groups              |
1 j+ |; k. h. b; Y" W8 S) K9 b| auth_user_user_permissions    |9 `( q0 S# n3 P3 P7 T6 v
| django_admin_log              |) v7 P! H+ Y+ E  M& `/ g+ [
| django_content_type           |
) \1 P" o, X0 U| django_migrations             |2 c1 s. ]$ \; {% [0 W2 \% b
| django_session                |' _, u; v2 U" ?" Z! f
| sight                         |
9 `9 F2 D( N; o* [, O: P( h- i| sight_comment                 |$ f: _; [6 X+ N  Y; R
| sight_info                    |
6 {1 j! N) J7 J0 ^4 c7 V| sight_ticket                  |
" g: J' S5 z. g$ o/ j/ {+ j| system_image_related          |: q7 {& _! ]" V# ~2 R2 B
| system_slider                 |' h; M$ h8 p8 @2 J# b
+-------------------------------+
9 M+ l8 g+ u' ?. l& l21 rows in set (0.002 sec)
1 J* q, {  z1 ^, m: k( J, S- S) j

: s- i; q0 e% Z6 y- [- b' AMariaDB [tripsql]> delete from django_migrations where app='order';
. [) t" n% v/ |Query OK, 2 rows affected (0.004 sec)2 R2 f% t+ Z$ q3 S: G/ P( m
1 F/ d, \0 I" F3 g8 E3 p
MariaDB [tripsql]> exit
# x7 q9 T  }( H8 O' ^( _# `) RBye
; K/ d1 q- \  {
7 A0 T/ E% K: t& `7 N(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py migrate order5 X; Q' G% L& d) o
Operations to perform:4 u; ^( L! M& U8 {  {
  Apply all migrations: order
% W: j& f  T) L) Z8 vRunning migrations:
5 z( H; g$ z) y: c( n  Applying order.0001_initial... OK
2 Z4 D; T9 K7 D# T8 {$ @( a8 H* Q9 p% I- C5 E$ E
(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>  \/ m: d) T* D% E3 C
这次成功同步过去了。  e  s+ j& X* `3 w  z

# L  x0 V% Z: e( s6 I. {7 h  ^7 K! i
- W8 i, }- s, G1 Q$ j& o
2 w1 Q5 j  B2 Z% R! h( J3 ?3 S! i; p2 u
+ {" U/ `( U  F! K) Z# |

  x) D# f; \% e+ q8 M* ~, F! S& k$ `) s& u5 K$ K: G3 h

2 N3 S4 c2 U, w6 C! v(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py migrate order zero# x) v& T, Y4 h4 c! y* {
Operations to perform:
# L/ @  o  O# K1 ?- A8 c- H  Unapply all migrations: order
: c& ?9 k/ m4 y+ oRunning migrations:
; i; [! [. K9 g6 l) ]1 L- d0 P  Rendering model states... DONE
) B' ?2 t' y" l& ?$ d1 j  Unapplying order.0001_initial... OK
" b7 u' u& h: n" P& m
$ ?8 ]) w0 y9 G; v: d( K! \(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py migrate order zero
  q! w. ~" x. h2 |2 ]9 A0 Z" mOperations to perform:: z6 d" k4 B5 B- \+ \* f/ D
  Unapply all migrations: order; {0 a+ n. Y1 D6 ^2 J
Running migrations:: c2 S, A* q& O. ]& {' w: Y
  No migrations to apply./ {$ C& Z# @+ K4 p9 {  }0 v' d3 _* N

& X, M/ K( H+ s  ^9 f( l* o( k. I(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py makemigrations --empty order. }6 `+ B$ p6 D" y6 ^
Migrations for 'order':" l( q% L, ]; W9 ?% C4 S, H+ M
  order\migrations\0002_auto_20250718_1752.py  o' f/ k, T% A  b$ H

- N$ w; [/ ~, G) @" K- W(python3.8.2-vitual) C:\Users\admin\Desktop\deskdirectory\trip>python manage.py dbshell7 [. O# A& t; B  x  ?7 d
Welcome to the MariaDB monitor.  Commands end with ; or \g.$ P6 I" O; c9 y$ s) J
Your MariaDB connection id is 162
& \* U0 p1 N2 D2 _Server version: 11.5.1-MariaDB mariadb.org binary distribution+ [( `% ^" l% W( u; \

2 r7 x6 D& }7 c+ I( eCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
- r/ X- d& L! H! x8 g6 b4 F$ I* l) v& L) N
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
8 I2 J' O8 g$ F- C) N; ]6 t" i8 U$ ^$ z9 R" y  l. Z
MariaDB [tripsql]> delete from django_migrations where app='order';
6 n0 _0 m0 R! x% tQuery OK, 0 rows affected (0.001 sec)
+ k$ Z' `7 d: O+ S1 e8 o1 B$ V+ l
MariaDB [tripsql]>
) h) W8 R: V+ a& }. o. D; B! [, F; J! X. G& U* C6 Z
+ k# Z) o+ E' \) }2 c0 C
5 O( n* u+ ^) ~

% k: T3 O3 D. Y, K, T, S8 H. _) ?9 v% P0 p: `% x$ s

8 \9 c' B4 E+ ~  [! s5 c

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-7-18 17:22:08 | 显示全部楼层
问题描述:$ D- g3 A% Z. c" t, V
已有的model,修改之后,想重新建模,于是将migrations文件夹中除__init__.py之外其他文件都删掉,再次执行以下步骤python manage.py makemigrations确认成功,执行python manage.py migrate,提示No migrations to apply. 表示一脸懵逼。再次修改,指定表名,再次尝试,发现问题依旧,表示二脸懵逼0 y7 _" o2 \5 j# H
! r, K; ~, o$ H# U! {7 G
排查过程" _- K, F3 O( W' P* P
python manage.py dbshell 进到数据库里面,查看是否表已存在 & A! n" Y% j' r" ^. c1 l0 q/ y
结果:表不存在: X( W) O7 x3 }9 t. _0 o
检查migrations文件 6 Z; c- I  a0 J. i" Z" v+ I
结果:文件没问题
3 @! ~- b) `' q  ]* \# Z百度 google 各种搜,乱投医,各种尝试
! ^6 t" |+ I% A1 J  E* h9 q解决方案
$ V, }7 w( B5 B) Apython manage.py dbshell 进到数据库中,执行delete from django_migrations where app='your_appname';) ^$ ]  w! S$ w5 e" {3 L; H* ?
python manage.py makemigrations(若migrations文件未删除,可不执行这一步)3 w8 G4 y& x' h
python manage.py migrate 好啦,大功告成  }) Q8 @' A3 ?  p
原因分析
5 V& n, B( ]9 \+ C9 c; v: J查看django_migrations表结构 4 K. A& o9 K0 X9 h' m9 }5 R
建表语句:
8 t! N& K, Z$ p! x+ c* yCREATE TABLE "django_migrations" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "app" varchar(255) NOT NULL, "name" varchar(255) NOT NULL, "applied" datetime NOT NULL);
( B9 ~. t0 \* d5 _2 K原因
3 s2 ]; P' J, }" f- X6 l造成多次应用migrations失败的原因是,当前model是修改过的,原来的migrations已经被我删除,但是,重新生成的migrations使用递增整数记名,所以,在django_migrations表中0001,0002等前面几个数字的文件都已被记录,在Django看来,被记录了就相当于已应用,所以,会出现刚开始的No migrations to apply.0 K2 v7 \) n8 [4 y; e
避免方案
7 L3 E. Z. d/ M2 p6 J4 Z' ?, \有强迫症删除migrations文件的同学(比如我),请同时到数据库中删除相应记录
, S1 H8 ~2 r+ ?/ L没有强迫症的同学,可以继续生成新的migrations,旧的就不必理会了1 E, W& O% g  A4 I9 l, y, D
题外话" ]% S  m. t  G9 i3 @
执行python manage.py migrate之后,可以使用python manage.py sqlmigrate appname migrations_num(例如python manage.py sqlmigrate user 0002)查看当前migrations文件对应的sql语句。
# w( E4 P8 V  Y( l* j& ^另外,在使用上述命令查看0002文件的sql语句时发现,django会新建一个表user_new,然后插入user表中的数据,再把user表删掉,再把user_new重命名为user。所以,修改model的时候,不必担心原有数据会丢失。

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2026-5-26 09:26:16 | 显示全部楼层
MariaDB [loogcn_data]> show tables;
) \& Q" ?5 v" W1 t  I+ M9 |9 y. E& k+-------------------------------+2 {  r6 K( }' E! O
| Tables_in_loogcn_data         |
% h* r( J8 s- n5 S7 F+-------------------------------+$ b7 J: h. c# O" H, P
| account_user                  |
% Z* B3 f7 m& r" R. {| account_user_groups           |1 C0 t/ \# _5 m* ^) V
| account_user_social           |/ e8 K: n2 c( @+ [. b% R/ l
| account_user_user_permissions |
6 `6 u; ^1 T8 o& D9 x& X| auth_group                    |2 K4 l4 S% I' Z6 U
| auth_group_permissions        |. R& y; [% X' |$ i4 V4 Q. {8 K
| auth_permission               |3 w- ^, Q4 `5 _+ i
| django_admin_log              |
8 b) j* g/ S+ P; j8 i& x' F| django_content_type           |9 z; q8 @5 [2 m. v
| django_migrations             |+ [; O: B* t+ t( S
| django_session                |
6 g/ ^1 X9 C8 U+-------------------------------+( x6 A  d! h' g
11 rows in set (0.001 sec): B9 c  k7 |3 l4 ]
5 c. w8 e) E7 K) e9 d3 Y2 f) m
MariaDB [loogcn_data]> select * from django_migrations;
1 j2 K% D* {7 M7 s1 [3 [: k+----+--------------+------------------------------------------+----------------------------+
, n) S) m! ?. N. d/ u# z| id | app          | name                                     | applied                    |
7 G9 B6 _4 h: B+----+--------------+------------------------------------------+----------------------------+
" W) e; _5 x  V9 x* i|  1 | contenttypes | 0001_initial                             | 2026-05-23 02:00:34.278182 |9 q; {/ d& s& }" z' n0 I
|  2 | contenttypes | 0002_remove_content_type_name            | 2026-05-23 02:00:34.505337 |1 N* n7 j/ x9 s/ Z/ e
|  3 | auth         | 0001_initial                             | 2026-05-23 02:00:35.411267 |; n' D( {' O* [7 u  S* w
|  4 | auth         | 0002_alter_permission_name_max_length    | 2026-05-23 02:00:35.567344 |
- R- A. G6 [; {) L2 M. O|  5 | auth         | 0003_alter_user_email_max_length         | 2026-05-23 02:00:35.573367 |
3 F: S6 E; V! Y|  6 | auth         | 0004_alter_user_username_opts            | 2026-05-23 02:00:35.578785 |
  f: @& F  l% c3 ]- p|  7 | auth         | 0005_alter_user_last_login_null          | 2026-05-23 02:00:35.584691 |
" r: n& U8 |" a4 N2 d$ L|  8 | auth         | 0006_require_contenttypes_0002           | 2026-05-23 02:00:35.585385 |
; Q! ]1 o; Q! K& D|  9 | auth         | 0007_alter_validators_add_error_messages | 2026-05-23 02:00:35.590374 |
% _& T7 ]1 k" r6 G| 10 | auth         | 0008_alter_user_username_max_length      | 2026-05-23 02:00:35.595604 |
  C2 ~+ T( @* O  }, E  a| 11 | auth         | 0009_alter_user_last_name_max_length     | 2026-05-23 02:00:35.605769 |5 S$ e2 Z$ `" B; w
| 12 | auth         | 0010_alter_group_name_max_length         | 2026-05-23 02:00:35.705389 |
6 X9 x; w$ W) R2 G1 O| 13 | auth         | 0011_update_proxy_permissions            | 2026-05-23 02:00:35.711556 |7 n8 M- Z* H* l" F7 L
| 14 | auth         | 0012_alter_user_first_name_max_length    | 2026-05-23 02:00:35.716632 |. s; P$ U  [8 o; v
| 15 | accounts     | 0001_initial                             | 2026-05-23 02:00:37.445274 |( Y1 M, C# n- ?0 o5 J$ ]. |
| 16 | admin        | 0001_initial                             | 2026-05-23 02:00:37.817254 |
2 a, t& J" |( n. H$ K| 17 | admin        | 0002_logentry_remove_auto_add            | 2026-05-23 02:00:37.827664 |* `8 H5 l- O! @9 V9 _2 L
| 18 | admin        | 0003_logentry_add_action_flag_choices    | 2026-05-23 02:00:37.836978 |9 B( ]0 b% o) ~. \% l! O
| 19 | sessions     | 0001_initial                             | 2026-05-23 02:00:37.991277 |
1 u0 ~1 i& e( R: D* u$ a2 l+----+--------------+------------------------------------------+----------------------------+
' G0 Z; n( s" |) j& |19 rows in set (0.001 sec)) v' b; G$ ~2 J2 K0 T- |$ T
1 H0 i% U$ i9 S$ C+ V
MariaDB [loogcn_data]> delete from django_migrations where app='accounts';
2 O* r  H8 G4 W  q1 ~Query OK, 1 row affected (0.001 sec)
' y3 S! X8 z1 _& h: f
  P! w0 o) X# t1 ?, xMariaDB [loogcn_data]> delete from django_migrations where app='contenttypes';; A7 C% v& _2 G3 ]
Query OK, 2 rows affected (0.000 sec)7 Y- t( X2 E( D% _( j" v& f

/ d- L3 K  r) b+ H* D$ c6 g! j) u* uMariaDB [loogcn_data]> delete from django_migrations where app='contenttypes ';* A5 c7 h! y8 v( a% V
Query OK, 0 rows affected (0.000 sec)- K/ d" c5 `# h' r! @4 v+ J% Z, c

; H  I! Z( }9 A8 i* OMariaDB [loogcn_data]> select * from django_migrations;; ]6 Y' \& W, H1 ?. w) e
+----+----------+------------------------------------------+----------------------------+
" H' C: a& P; [6 N| id | app      | name                                     | applied                    |
8 b; |5 |1 R9 p4 s+ x8 Z+----+----------+------------------------------------------+----------------------------+
4 J$ U/ L* q9 c- e* m|  3 | auth     | 0001_initial                             | 2026-05-23 02:00:35.411267 |# `" l  V' R4 d8 ^$ B* a$ I4 F, |
|  4 | auth     | 0002_alter_permission_name_max_length    | 2026-05-23 02:00:35.567344 |
3 c* L3 T) `! W1 u' T& w' l' P|  5 | auth     | 0003_alter_user_email_max_length         | 2026-05-23 02:00:35.573367 |
4 g$ c: P* l# m# q5 z8 x/ l- s|  6 | auth     | 0004_alter_user_username_opts            | 2026-05-23 02:00:35.578785 |9 i, a: z/ P$ G. V% F, r5 w
|  7 | auth     | 0005_alter_user_last_login_null          | 2026-05-23 02:00:35.584691 |! T) P; K# N- G% F$ `( n$ I
|  8 | auth     | 0006_require_contenttypes_0002           | 2026-05-23 02:00:35.585385 |9 e, y5 s! \7 \  _4 q4 |8 ^8 L+ L+ ]
|  9 | auth     | 0007_alter_validators_add_error_messages | 2026-05-23 02:00:35.590374 |$ |& u: N+ a" O
| 10 | auth     | 0008_alter_user_username_max_length      | 2026-05-23 02:00:35.595604 |+ ]' P( d& Q4 m" Z9 Z& r
| 11 | auth     | 0009_alter_user_last_name_max_length     | 2026-05-23 02:00:35.605769 |
, y6 r$ V  {; || 12 | auth     | 0010_alter_group_name_max_length         | 2026-05-23 02:00:35.705389 |
5 C; l) s7 c! |' y1 S5 T4 [- d| 13 | auth     | 0011_update_proxy_permissions            | 2026-05-23 02:00:35.711556 |
% |" [5 Z. }% {3 U8 ^  T8 O| 14 | auth     | 0012_alter_user_first_name_max_length    | 2026-05-23 02:00:35.716632 |# ], s4 c1 y8 f0 U4 }
| 16 | admin    | 0001_initial                             | 2026-05-23 02:00:37.817254 |" R; v! s* o6 G/ I6 J/ G. ^7 @/ b* `
| 17 | admin    | 0002_logentry_remove_auto_add            | 2026-05-23 02:00:37.827664 |% ?5 A9 I0 h, ?% q( g
| 18 | admin    | 0003_logentry_add_action_flag_choices    | 2026-05-23 02:00:37.836978 |
: G3 |# b0 y4 t| 19 | sessions | 0001_initial                             | 2026-05-23 02:00:37.991277 |, q! V' K( w/ Q% t
+----+----------+------------------------------------------+----------------------------+) ?% A& |! u8 M# V% ^2 f
16 rows in set (0.000 sec)) o; E6 \7 I1 l7 Y1 t3 v: b* C% L
! A8 G% b- d  j0 E9 t! g
MariaDB [loogcn_data]> delete from django_migrations where app=' sessions ';3 e8 P! F( z4 y6 p6 t
Query OK, 0 rows affected (0.001 sec)% Q: F1 K# `3 T# l( _/ k7 R' p
) F5 K. d9 ?: U% L, t6 q( R
MariaDB [loogcn_data]> delete from django_migrations where app='auth';
* B  }/ n. m* }4 ~& @Query OK, 12 rows affected (0.001 sec)) L9 R# ^* n+ ^4 c. J( B
" z: y/ i) T8 |$ ]6 r: U. R& O3 K
MariaDB [loogcn_data]> delete from django_migrations where app='auth' and app='admin';2 t) Y1 Z' ?8 N1 g2 Z( M0 N
Query OK, 0 rows affected (0.001 sec)( B$ m9 I9 Q8 T: a
$ D- i$ u3 b* j& K, T
MariaDB [loogcn_data]> select * from django_migrations;* S7 R& ]" J# q/ d4 h
+----+----------+---------------------------------------+----------------------------+
- d( j- k: [8 d: k. @* F! u| id | app      | name                                  | applied                    |
$ U/ `6 M: {# Z: f. w: s+----+----------+---------------------------------------+----------------------------+
7 W. m" A7 L' J| 16 | admin    | 0001_initial                          | 2026-05-23 02:00:37.817254 |
% G4 |9 v9 s9 p0 K5 x) C5 Q| 17 | admin    | 0002_logentry_remove_auto_add         | 2026-05-23 02:00:37.827664 |$ v0 p: X6 l4 q. I9 i' ]
| 18 | admin    | 0003_logentry_add_action_flag_choices | 2026-05-23 02:00:37.836978 |" ]4 p+ i! M- h1 |4 R1 e6 a7 q
| 19 | sessions | 0001_initial                          | 2026-05-23 02:00:37.991277 |$ J, w4 F0 ^3 @( o: w( }
+----+----------+---------------------------------------+----------------------------+# |9 v  b5 v& _9 f
4 rows in set (0.001 sec)
0 b+ F8 |; v7 N1 Y. J
- F8 R2 J2 z; BMariaDB [loogcn_data]> delete from django_migrations where  app='admin';
$ E  F0 C0 l2 \0 {5 Z) MQuery OK, 3 rows affected (0.000 sec)
) d0 D% q* p5 U) R6 J) ^! t3 \/ m* \( q4 a
MariaDB [loogcn_data]> select * from django_migrations;
6 ^0 H* ?8 k* L5 |6 M3 e. Y. m$ a# y- k+----+----------+--------------+----------------------------+
  W0 x# z7 I" S& b; e! V' @! p* K| id | app      | name         | applied                    |9 n- p1 c3 O) G
+----+----------+--------------+----------------------------+
' w& ^7 u  S, y' B# {3 j+ y9 A| 19 | sessions | 0001_initial | 2026-05-23 02:00:37.991277 |
5 v# n9 J2 h9 X+----+----------+--------------+----------------------------+. I6 ?( j6 M3 e/ X  ~
1 row in set (0.000 sec); b- G; T+ C  a) I3 U- i
7 G, G, G# }0 p) N9 B% H* w! T
MariaDB [loogcn_data]> delete from django_migrations where  app='sessions';6 N& c$ V) @8 N6 D  ]
Query OK, 1 row affected (0.001 sec): m( O* W8 v7 |% p, D
- _( s& J9 O8 R
MariaDB [loogcn_data]>! ?: o( K) \3 j8 `
清空所有的表,& R. Y& q8 p3 G- W, g7 G

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2026-5-26 09:27:29 | 显示全部楼层
进入 MySQL 终端,删掉当前数据库并重建:sqlDROP DATABASE your_database_name;8 C# P1 `; d, E
CREATE DATABASE your_database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
8 ]5 I8 h' ~4 W/ g1 K6 B0 r7 H请谨慎使用此类代码。重新在终端执行迁移命令:bashpython manage.py migrate
( u" S: K# q) b# [* o请谨慎使用此类代码。如果你使用了方案一或方案二后遇到了其他报错,请告诉我:这是新创建的项目还是维护中的老项目?数据库里是否有需要保留的业务数据?我会为你提供更精准的修复步骤。

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2026-5-26 09:33:03 | 显示全部楼层
MariaDB [loogcn_data]> show tables;; m7 {, G! m1 Z) ?: f" y8 N
+------------------------+4 M8 i4 m8 I( o2 f6 c
| Tables_in_loogcn_data  |
4 `) t4 ^9 a  n/ M- g# d9 g+------------------------+
5 ^! D& f9 l- }: y& s| account_user           |
' M0 @6 U( y3 R! c( v! \8 ^| auth_group             |
  \. G" x/ [; Q- l" y| auth_group_permissions |6 f, Q) o3 W+ ]6 }6 S
| auth_permission        |
  J1 v4 ]  @8 R; v% E| django_admin_log       |; R* [3 e* i+ Q* e" ^
| django_content_type    |8 [: U) r% \) p7 R; {) O0 W
| django_migrations      |
$ w5 s+ ~, Z. M- j| django_session         |
$ T' X( v7 S" z; f+------------------------+
) F1 I9 Q" x# r: E8 rows in set (0.001 sec)7 g+ o; t: F: d6 R, l

0 K6 V) z( R5 ], nMariaDB [loogcn_data]> drop table if exists auth_group_permissions;' B6 C" b/ q7 g4 L3 ]
Query OK, 0 rows affected (0.058 sec)
% E. u: z; m6 F) A- J# e% ?1 y
. u$ Q" d  ^7 b2 _" {MariaDB [loogcn_data]> drop table if exists django_admin_log;7 g  G4 p4 n3 g1 y0 [/ X
Query OK, 0 rows affected (0.056 sec)# \" F0 s5 x$ q, {4 e0 N! d* y# r

- F+ m3 E2 k; e! l" }8 y$ N8 }) PMariaDB [loogcn_data]> drop table if exists auth_permission ;
9 j$ y& x; E5 n8 O: o" k; Z7 E3 {# mQuery OK, 0 rows affected (0.061 sec)$ G/ n! l' Z( V- v0 T

3 n7 B+ }: C/ T& Y7 AMariaDB [loogcn_data]> drop table if exists account_user ;: n% z& X. T, |0 |  {  n% l4 d
Query OK, 0 rows affected (0.060 sec)" t$ t1 Q% {( l3 D2 k
+ R; H  C( ?2 x0 R
MariaDB [loogcn_data]> drop table if exists  auth_group ;2 A+ f4 Q& j$ @' v  g8 [6 Q
Query OK, 0 rows affected (0.055 sec). b4 I( T) m3 s6 a4 L
0 q& ~4 i; v& @' Y3 c3 }
MariaDB [loogcn_data]> drop table if exists  django_session;" O& M: U+ S3 z6 a( u$ G
Query OK, 0 rows affected (0.051 sec)! Y+ n, u: U6 e# s6 c
8 @& z& A' S, z& s+ n3 T: I
MariaDB [loogcn_data]> drop table if exists django_content_type;' p$ I% |+ Z8 Z5 d# F' T5 r: R
Query OK, 0 rows affected (0.052 sec)
9 `& `9 A, H+ U* z
% T2 C& b( P, v% GMariaDB [loogcn_data]> drop table if exists django_migrations ;
5 D) t9 j1 J& {6 q* u/ o' EQuery OK, 0 rows affected (0.068 sec)
" T4 J( W7 G( J& Y# l& P
1 ?: q+ t2 X. S8 VMariaDB [loogcn_data]> show tables;
" Z9 m1 e; k1 D( _, L1 p. lEmpty set (0.001 sec)/ H/ B) s& I6 C  ]
& F7 J* Z) [* O6 @
MariaDB [loogcn_data]>8 ^3 H* w3 [( n$ C
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 00:31 , Processed in 0.020496 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表